Re: Best practice for creating a temporary file
Re: Best practice for creating a temporary file
- Subject: Re: Best practice for creating a temporary file
- From: "email@hidden" <email@hidden>
- Date: Tue, 02 Sep 2014 17:50:54 +0000
Probably NSURLSessionDownloadTask fits this requirement. It downloads the data to a temporary file which can be read or moved to a permanent location. The temporary file gets deleted as soon as control returns from the completion handler.
------Original message------
From: Jens Alfke <email@hidden>
To: "email@hidden dev" <email@hidden>
Date: Tuesday, September 2, 2014 9:47:37 AM GMT-0700
Subject: Best practice for creating a temporary file
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
_______________________________________________
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