iphone - NSFileManager 中是否有任何方法可以仅获取某些字节范围的文件内容

标签 iphone ios file-io nsfilemanager fseek

我有一些大小为 6.7GB 的文件,甚至更多(这些是视频文件)。 我想将文件数据 block 发送到我的服务器,所以我目前所做的是:

contents = [fileManager contentsAtPath:path];
if (mFileOffset<[contents length]) {
NSRange range = NSMakeRange(mFileOffset, (allowedSize>[contents length]?[contents length]:allowedSize);
contents =[contents subdataWithRange:range];

但是,这会产生内存问题:

malloc: *** mmap(size=616927232) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
APP(2700,0x4136000) malloc: *** mmap(size=616927232) failed (error code=12)
*** error: can't allocate region

c++ 中是否有类似fseek 的方法,以便我只读取指定范围内的文件字节?

最佳答案

NSFileHandle中有一个方法同步读取指定字节数的数据。

-[NSFileHandle readDataOfLength:]

寻求:

– offsetInFile
– seekToEndOfFile
– seekToFileOffset:

关于iphone - NSFileManager 中是否有任何方法可以仅获取某些字节范围的文件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15744788/

相关文章:

c - 从文件中读取格式化字符串到 C 中的数组

iphone - 每 n 分钟在标签中显示 NSString

iphone - iOS 应用内购买 - "Invalid Product ID"处于发布版本,而非开发版本

iphone - 使用 CGRectMake 移动 subview 会导致崩溃

iphone - 单击 "OK"后首次运行时 GPS 未启动

java - 调用 FileWriter 的单元测试方法

iphone - 无法编译连接iOS5

ios - UITableView.reloadRows 在 Timer.scheduledTimer 内部调用时重置行动画类型

iphone - 一个 iOS 应用程序甚至可以访问另一个应用程序的缓存目录吗?

python - select.select() 与常规文件