[英]initialising NSInputStream from a particular portion of file (copied in Document directory)?
我正在從iOS應用程序上傳一個大文件,並且文件傳輸是按塊上傳。 我正在使用以下代碼初始化NSInputStream for Chunks。
// 例如
NSInteger chunkCount = 20;
for(int i=0; i<chunkCount; i++) {
NSFileHandle *handle = [NSFileHandle fileHandleForReadingAtPath:filePath];
[handle seekToFileOffset:(unsigned long long)i * (chunkCount == 1?fileSize:chunkSize)];
NSData *fileData = [handle readDataOfLength:chunkSize];
NSInputStream *iStream = [[NSInputStream alloc]initWithData:fileData];
}
但是我想知道是否可以使用NSInputStream方法,通過該方法可以從文件Stream而不是NSData的范圍初始化iStream。
謝謝
文件流具有NSStreamFileCurrentOffsetKey屬性,用於指定讀取偏移量。
NSInputStream *s = [NSInputStream inputStreamWithFileAtPath:path];
[s setProperty:offset forKey:NSStreamFileCurrentOffsetKey];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.