0

I am uploading a large file from my iOS app and file transfer is in chunk upload. i am using the below code to initialise NSInputStream for Chunks.

// for example

NSInteger chunkCount =  20;
for(int i=0; i<chunkCount; i++) {
  NSFileHandle *handle = [NSFileHandle fileHandleForReadingAtPath:filePath];
  [handle seekToFileOffset:(unsigned long long)i * (chunkCount == 1?fileSize:chunkSize)];
  NSData *fileData = [handle readDataOfLength:chunkSize];
  NSInputStream *iStream = [[NSInputStream alloc]initWithData:fileData];
  }

But I'd like to know if I can have a method of NSInputStream by which i can initialise iStream from the range of file Stream rather than NSData.

Thanks

iOS_Developer
  • 495
  • 4
  • 20
  • Theoretically you could subclass NSInputStream, but that seems to be tricky, see http://bjhomer.blogspot.de/2011/04/subclassing-nsinputstream.html. – Martin R Apr 10 '14 at 07:44

1 Answers1

1

There is NSStreamFileCurrentOffsetKey property for file streams to specify read offset.

NSInputStream *s = [NSInputStream inputStreamWithFileAtPath:path];
[s setProperty:offset forKey:NSStreamFileCurrentOffsetKey];
Pavel Osipov
  • 2,067
  • 1
  • 19
  • 27