在objective-c中只从磁盘读取一部分文件 [英] Read only a portion of a file from disk in objective-c

查看:133
本文介绍了在objective-c中只从磁盘读取一部分文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NSInputStream读取一个非常大的文件,并将它们发送到数据包中的设备。如果接收方没有收到数据包,我可以用一个数据包号码发回给发送方,代表丢失数据包的起始位置(字节)。

I am reading a very large file using a NSInputStream and sending them to a device in packets. If the receiver does not get a packet, I can send back to the sender with a packet number, representing the starting location in bytes of the packet missing.

我知道一个NSInputStream无法回放并获取数据包,但还有另一种方法可以获取所请求的字节范围而无需将整个大文件加载到内存中吗?

I know an NSInputStream cannot rewind and grab the packet, but is there another way to grab the requested byte range without loading the entire large file into memory?

如果有[NSData dataWithContentsOfFileAtPath :inRange]方法,它会很完美。

If there was a [NSData dataWithContentsOfFileAtPath:inRange] method, it would be perfect.

推荐答案

你可以使用NSInputStream回放:

You can rewind with NSInputStream:

[stream setProperty:[NSNumber numberWithInt:offset]
             forKey:NSStreamFileCurrentOffsetKey];

这篇关于在objective-c中只从磁盘读取一部分文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆