summaryrefslogtreecommitdiff
path: root/SmartDeviceLink
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2017-04-06 17:15:00 -0400
committerNicoleYarroch <nicole@livio.io>2017-04-06 17:15:00 -0400
commit6459fa32a6520cd1cdfef9d5bce89b26708df86e (patch)
tree3673c1a19097920402f9f4808873ec812646b4d0 /SmartDeviceLink
parentad98918058a260ca8b1e7c1bd6c4e234667e1d00 (diff)
downloadsdl_ios-6459fa32a6520cd1cdfef9d5bce89b26708df86e.tar.gz
Test cases work!
Signed-off-by: NicoleYarroch <nicole@livio.io>
Diffstat (limited to 'SmartDeviceLink')
-rw-r--r--SmartDeviceLink/SDLUploadFileOperation.h2
-rw-r--r--SmartDeviceLink/SDLUploadFileOperation.m25
2 files changed, 17 insertions, 10 deletions
diff --git a/SmartDeviceLink/SDLUploadFileOperation.h b/SmartDeviceLink/SDLUploadFileOperation.h
index 6922211d1..0369f3814 100644
--- a/SmartDeviceLink/SDLUploadFileOperation.h
+++ b/SmartDeviceLink/SDLUploadFileOperation.h
@@ -30,8 +30,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (instancetype)initWithFile:(SDLFileWrapper *)file connectionManager:(id<SDLConnectionManagerType>)connectionManager;
-- (void)start:(void (^)(BOOL success))completion;
-
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLUploadFileOperation.m b/SmartDeviceLink/SDLUploadFileOperation.m
index 0391cd066..73ae7e2bc 100644
--- a/SmartDeviceLink/SDLUploadFileOperation.m
+++ b/SmartDeviceLink/SDLUploadFileOperation.m
@@ -55,12 +55,6 @@ NS_ASSUME_NONNULL_BEGIN
[self sendPutFiles:self.fileWrapper.file mtuSize:[SDLGlobals sharedGlobals].maxMTUSize withCompletion:self.fileWrapper.completionHandler];
}
-- (void)start:(void (^)(BOOL success))completion {
- [super start];
-
- [self sendPutFiles:self.fileWrapper.file mtuSize:[SDLGlobals sharedGlobals].maxMTUSize withCompletion:self.fileWrapper.completionHandler];
-}
-
- (void)sendPutFiles:(SDLFile *)file mtuSize:(NSUInteger)mtuSize withCompletion:(SDLFileManagerUploadCompletionHandler)completion {
// iStream is NSInputStream instance variable
@@ -103,12 +97,14 @@ NS_ASSUME_NONNULL_BEGIN
// Get a chunk of data from the input stream
NSError *error = nil;
- NSData *dataChunk = [self getDataChunkWithSize:putFileLength inputStream:self.inputStream error:&error];
+ NSUInteger dataSize = [self getDataLengthForOffset:currentOffset fileSize:fileSize mtuSize:mtuSize];
+ NSData *dataChunk = [self getDataChunkWithSize:dataSize inputStream:self.inputStream error:&error];
if (dataChunk == nil) {
+ // TODO: - ????? Add error message here!
return completion(NO, bytesAvailable, streamError);
}
putFile.bulkData = dataChunk;
- currentOffset += putFileLength;
+ currentOffset += dataSize;
// Send the putfile
NSLog(@"entering: %@", self);
@@ -150,6 +146,19 @@ NS_ASSUME_NONNULL_BEGIN
return putFileLength;
}
+- (NSUInteger)getDataLengthForOffset:(NSUInteger)currentOffset fileSize:(unsigned long long)fileSize mtuSize:(NSUInteger)mtuSize {
+ NSInteger dataSize = 0;
+ NSUInteger fileSizeRemaining = (NSUInteger)(fileSize - currentOffset);
+ if (fileSizeRemaining < mtuSize) {
+ // The file length remaining is smaller than the max data chunk sized allowed. The putfile expects the length parameter to match the size of the last data chunk being sent.
+ dataSize = fileSizeRemaining;
+ } else {
+ // When the file length remaining is greater than the max data chunk sized allowed, and the offset is not zero, the putfile expects the length parameter to match the size of the data chunk being sent.
+ dataSize = mtuSize;
+ }
+ return dataSize;
+}
+
- (nullable NSData *)getDataChunkWithSize:(NSInteger)size inputStream:(NSInputStream *)inputStream error:(NSError **)error {
uint8_t buffer[size];
NSInteger bytesRead = [inputStream read:buffer maxLength:size];