简体   繁体   English

下载后重新组合NSData对象

[英]Recombining NSData objects after a download

I broke up a file into 50 mb packets on the server side and when I receive it on the iPad, I receive as NSData object through NSURLConnection. 我在服务器端将文件分解为50 mb数据包,当我在iPad上收到该文件时,我通过NSURLConnection收到了NSData对象。 To restitch the data, do I create an empty NSMutableData object and just appendData the packets back together in order? 要重新整理数据,我是否要创建一个空的NSMutableData对象,然后将数据包按顺序追加到一起appendData? Or am I supposed to use NSFileHandle, write to file, seek to end of file, write next file, seek to end of file, rinse, repeat? 还是我应该使用NSFileHandle,写入文件,寻找文件结尾,写入下一个档案,寻找文件结尾,冲洗,重复? Thanks! 谢谢!

It really depends on the memory constraints. 这实际上取决于内存限制。 If the x00M files are too much to handle in memory with the NSData object you will have to go the second route (which I think is a great approach). 如果x00M文件太多,无法使用NSData对象在内存中处理,则必须走第二条路线(我认为这是一种很好的方法)。 You can check with Instruments if you are within acceptable limits. 您可以通过仪器检查是否在可接受的范围内。

Seeing that you want to do this on an iPhone, it is very likely that you will have to do it via the file system. 看到要在iPhone上执行此操作,很有可能必须通过文件系统执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM