Does NSFileWrapper load everything into memory?

Suppose I have an NSFileWrapper directory. This directory consists of several levels of directories and files. Some of the files are large. Are all these files loaded into memory or are they lazily loaded?

If they are loaded into memory, are there any alternatives to NSFileWrapper with similar functionality that will not load files into memory? Can I connect UIDocument to a UIDocument ?


This is for a document-based application that uses UIDocument that syncs with iCloud. A document may have images and videos embedded in it. Each image / video has a preview image (thumbnail) that is shown in the HTML document. Full-size images or videos should not be loaded into memory, but loaded on demand.

I also need a way to add a resource without loading it into memory. Something like "initWithAsset: (ALAsset *)" would be ideal.

+3
source share
2 answers

This is not entirely clear from the documentation, but I'm 99% sure that NSFileWrapper will display all memory cards. The main use case for NSFileWrapper is embedding files inside documents, where you probably need access to the specified file at any time.

What are you trying to use file wrapper for? I assume that if you create an entire directory, it is not necessary to insert the media inside the document, but maybe I'm wrong. If you might talk a little more about your use case, as this will affect the alternatives you can use.

+4
source

I made an application a while ago that generates a video. This video was saved in a specific file format using a subclass of UIDocument.

The only way to make the application non-exhaustive when executing contentsForType:error: was to output the video to a file in dmp dmp and run the file with the video URL using NSFileWrapperReadingWithoutMapping -option to prevent it from loading the video into memory and simply copy to file.

 - (id)contentsForType:(NSString *)typeName error:(NSError **)outError { if (self.fileWrapper == nil) { self.fileWrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:nil]; } if (self.videoURL != nil) { NSError *fileReadError; NSFileWrapper *videoFileWrapper = [[NSFileWrapper alloc] initWithURL:self.videoURL options:NSFileWrapperReadingWithoutMapping error:&fileReadError]; if(fileReadError){ NSLog(@"File read error: %@", [fileReadError localizedDescription]); }else { [videoFileWrapper setPreferredFilename:@"video.mov"]; [self.fileWrapper addFileWrapper:videoFileWrapper]; } } //... } 
+7
source

Source: https://habr.com/ru/post/970408/


All Articles