我有一些大小为 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/