If you want to download the file by passing an instance of NSInputStream to NSURLRequest.HTTPBodyStream , you really need to subclass NSInputStream and only pass the bytes that you want to load. Using NSFileHandle is not an option here.
Subclassing NSInputStream to work with NSURLRequest is pretty tricky, but fortunately there’s a great blog post on how to do this.
Here you can find a ready-to-use subclass of NSInputStream .
You can send the ChunkInputStream other NSInputStream reading the file and pass in the starting position and the number of bytes read.
Swift example:
let fileInputStream = NSInputStream(fileAtPath: "/tmp/readme") let inputStream = ChunkInputStream(inputStream: fileInputStream) inputStream.startPosition = 2097152 inputStream.readMax = 1048576
source share