Re: Saving only required files in a file wrapper?
Re: Saving only required files in a file wrapper?
- Subject: Re: Saving only required files in a file wrapper?
- From: Keith Blount <email@hidden>
- Date: Wed, 7 May 2008 17:26:12 -0700 (PDT)
Thanks again for the reply.
Now I'm thinking that maybe just overriding -writeToURL:ofType:error: may be the way to go. In this method, I should just be able to write any changed files out. I hope.
The trouble with all of these methods is that they tell you not to rely on fileURL. But in my situation, I want to be able to rely on it. A window can't be opened before a package is created in my app, so at no point can the user call a load or save without the document existing on disk. I don't want - at any point- the document architecture to do anything with that file package. All I ever want to do is access individual files within it. There just seems to be nothing on this anywhere. But I'm hoping that if I put everything in this method, and then just as a failsafe, override the other NSDocument -write... methods to do absolutely nothing, that things will work okay. What I don't want to do is have to copy everything in the package and save the whole thing. For users who have projects that are hundreds of megabytes, this means a slow save. The whole point of the file format I have chosen is that it should mean quick saves - only saving individual
files within the wrapper that have changed - and safety, in that all the text is stored in individual files inside the wrapper. But nothing in the documentation seems to support this sort of setup. Still, I'll experiment with -writeToURL:... and see how it goes...
Thanks again!
All the best,
Keith
----- Original Message ----
From: Ken Thomases <email@hidden>
To: Keith Blount <email@hidden>
Cc: email@hidden
Sent: Wednesday, May 7, 2008 10:46:39 PM
Subject: Re: Saving only required files in a file wrapper?
Hi,
On May 7, 2008, at 3:08 PM, Keith Blount wrote:
> Many thanks for your response...
Sure thing. I'm happy to flail in the dark and guess wildly with the
best of them. ;)
> Hmm, I think you're right. I overrided -saveDocument: because it
> looked as though -writeToURL: and all of the other -write... methods
> expected you to write all the data at any one time. It's possible
> for my file packages to run to hundreds of megabytes, so I only ever
> want to write the changed files at any save point (usually only ever
> one or two RTFD files within the package actually require saving at
> any one time). There's not much in the docs about doing this -
> everything I can find seems to assume that you will save everything,
> even when it comes to packages (as file wrappers), at once, which is
> why I took a screwy way.
Yeah, it's hard to see how one can accomplish what you're trying to do.
I wonder... what happens if you compose a directory NSFileWrapper
from an existing directory (which will recursively fill it with file
wrappers referencing the directory's contents), then remove the
wrappers for the individual items you want to replace, then add new
file wrappers for those items, then save that whole file wrapper to
the desired destination location? Are there any smarts in there to
avoid doing a full copy of all of the items which weren't changed,
perhaps using hard links or the like?
> I still wonder what the best way of doing it is. -
> writeToURL:ofType:forSaveOperation:originalContentsURL:error: perhaps?
Well, that seems to give you the greatest flexibility, and gives you
both the new and old URLs, but -- by the very fact that you're given
two URLs -- the explicit fact is that you are creating a new document
on disk rather than doing a minimal modification of the old one. So,
you'd have to perform the copy of all of the parts that are the same
between the two, which is what you're trying to avoid.
> Also, is it possible that -writeToURL: is getting called behind the
> back of -saveDocument:? I considered this but assumed (always a bad
> mistake) that it would be safe as I thought that all of the -
> write... methods did nothing unless you overrode them.
I don't know. That's certainly one of the possibilities I
considered. I think you have to assume it's possible. For instance,
I would not expect the auto-save features of NSDocument to go through -
saveDocument:. -saveDocument: is an action method, intended to be
triggered by the Save menu item (and similar GUI controls). So, I
would expect that it would have all sorts of high-level functionality
like running a save panel if the document hasn't been saved before.
Because of that, the framework wouldn't use it when it needs to do
something low-level.
Cheers,
Ken
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
_______________________________________________
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