diff options
| author | NicoleYarroch <nicole@livio.io> | 2017-04-06 17:15:00 -0400 |
|---|---|---|
| committer | NicoleYarroch <nicole@livio.io> | 2017-04-06 17:15:00 -0400 |
| commit | 6459fa32a6520cd1cdfef9d5bce89b26708df86e (patch) | |
| tree | 3673c1a19097920402f9f4808873ec812646b4d0 /SmartDeviceLink/SDLUploadFileOperation.m | |
| parent | ad98918058a260ca8b1e7c1bd6c4e234667e1d00 (diff) | |
| download | sdl_ios-6459fa32a6520cd1cdfef9d5bce89b26708df86e.tar.gz | |
Test cases work!
Signed-off-by: NicoleYarroch <nicole@livio.io>
Diffstat (limited to 'SmartDeviceLink/SDLUploadFileOperation.m')
| -rw-r--r-- | SmartDeviceLink/SDLUploadFileOperation.m | 25 |
1 files changed, 17 insertions, 8 deletions
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]; |
