I am having a 100 MB of data in a single file. This 100 mb data will be divided virtually. i.e., I need to create an NSInputStream which points to different 5MB chunks. This is possible by creating the stream with NSData.
But rather I'd like to know if I can have a NSInputStream which points to a range of data in the file ?
If you want to upload a file by passing a
NSInputStream
instance toNSURLRequest.HTTPBodyStream
you indeed have to create a subclass ofNSInputStream
and only stream the bytes you want to upload. UsingNSFileHandle
is not an option here.Creating a subclass of
NSInputStream
that works withNSURLRequest
is quite tricky, but fortunately here is a great blog post about how it can be accomplished.Here you can find a ready to use subclass of
NSInputStream
for this purpose.You can feed
ChunkInputStream
with anotherNSInputStream
reading a file and pass start position and number of bytes to read.Swift example: