Best practice for creating a temporary file
Best practice for creating a temporary file
- Subject: Best practice for creating a temporary file
- From: Jens Alfke <email@hidden>
- Date: Tue, 02 Sep 2014 09:47:37 -0700
I'm downloading data that will eventually be saved as a file in a specific directory. During the download I write the data to a temporary file since it can be arbitrarily large; then on completion I move the temporary file to its final location. So I need to locate a temporary-files directory that is on the same volume as the final location.
So far I've been using NSItemReplacementDirectory, but this has a couple of problems:
(1) It creates a new visible directory right next to the permanent location, called "(A Document being saved by $APP") where $APP is the app name.
(2) This directory doesn't get cleaned up by the OS. I have to remember to delete it, and if the app unexpectedly quits it gets left behind and then the next launch creates another of these directories.
What's the alternative? I don't want to use NSTemporaryItemsDirectory because that's always on the boot volume, and the final location of the file might not be; in that case the move operation will turn into a copy-and-delete which will be non-atomic and could be slow.
It looks as though there _is_ a per-volume temporary-items directory, because on my non-boot partition I see a top-level invisible directory called ".TemporaryItems" with a subfolder for each user-ID. But how do I find it programmatically?
—Jens
_______________________________________________
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