Question

I'd like write a file to disk using multiple NSOutputStreams (each one in a different thread). I know how to handle the threading issue, but I can't figure out what to use to write different byte-ranges to a single file at the same time.

For example, say the target file will be 100 MB on disk when the write process is complete. I have 4 threads with 4 streams (we'll call them s0, s1, s2, and s3) that want to write 25MB to the target file. I want each stream (s0-3) to be able to write at the same time to their respective target byte ranges (e.g. s0 writes from 0MB-25MB, s1 from 25MB-50MB, etc.). Each stream is independent, so I can tell which stream will receive bytes or when.

Thanks.

Was it helpful?

Solution

Use NSFileHandle and its -seekToFileOffset: method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top