Re: Using the Document Architecture and Reading files one buffer at a time
Re: Using the Document Architecture and Reading files one buffer at a time
- Subject: Re: Using the Document Architecture and Reading files one buffer at a time
- From: Graham Cox <email@hidden>
- Date: Fri, 24 Jul 2009 13:36:49 +1000
Actually, I think you'll need to cut in before the file wrapper gets
made - it looks like it does load the file content into memory.
So, instead, override - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:
(NSString *)typeName error:(NSError **)outError
and then you can get at the original URL before the file wrapper gets
created, and do whatever. Note that NSData has the method
+ (id)dataWithContentsOfURL:(NSURL *)aURL options:(NSUInteger)mask
error:(NSError **)errorPtr
and one of the options is NSMappedRead which allows you to memory map
the file, or you can get a NSFileHandle using the URL's path, which
would be another way to read from the file in sections.
--Graham
On 24/07/2009, at 1:24 PM, Graham Cox wrote:
On 24/07/2009, at 5:46 AM, Korei Klein wrote:
I'm trying to use the document architecture in an application that
will create documents for some very big files. I'd like not to
have an entire file in memory at once. To use the document
architecture, I'm subclassing NSDocument and overriding the
readFromFileWrapper method. As far as I can tell, there is no way
to use a FileWrapper object to read a file one buffer at a time.
Can I find out a filename, or a filehandle from a FileWrapper?
Alternatively, is there any way to have an NSDocument using the
document architecture which reads its files one buffer at a time?
Have you looked at the API for NSFileWrapper? You can get the
filename, and (I guess) as long as you don't call -
regularFileContents, you can use whatever NSData methods make sense
to get at parts of the file on demand. There's no requirement that
NSDocument actually loads the whole file - you can return YES to
tell it everything went OK, and retain and manage the data
internally however you see fit.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden