Re: Question about zipping files
On 2/15/10 4:50 PM, Gideon King said: Thanks for the suggestion. Have not encountered Scripting Bridge before and have very little experience or understanding of AppleScript and no knowledge of Apple Events or what they do. I had a vague notion that Apple Events were pretty much old technology from before OSX, but now I see that it appears that it's the foundation of AppleScript. I guess I should take time to look into these technologies sometime (I come from a NextStep/OpenStep/WebObjects background)... AppleEvents date from System 7, so yeah, they're pretty old. But that should not automatically disqualify them. UNIX and NeXTStep are old too. :) Is there any particular reason you say to stay away from NSTask? I only meant that it's generally preferable to use an API when you can. ex: don't copy files using NSTask and 'cp', because NSWorkspace can copy files. Scripting Bridge seems like an interesting option, but after having generated the headers for Finder, I could not see a command there for compressing files. I guess it's not scriptable. The Finder is scriptable, but not every command can be scripted. I looked quickly with AppleScript Editor, and indeed Finder does not seem to expose 'compress'. Oh well. I'd file a bug asking that NSWorkspaceCompressOperation be implemented. -- Sean McBride, B. Eng s...@rogue-research.com Rogue Researchwww.rogue-research.com Mac Software Developer Montréal, Québec, Canada ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Question about zipping files
Gideon King wrote: 1. Use NSTask to create a zip file, passing in as arguments all the filenames to zip. My question about this would be whether I would run into any restrictions with the length of the command which well be beyond the old 1024 character limits (not sure if any command line argument limits are still extant). I would think this would be the most efficient way to do it (both time and memory/storage wise), so long as there are no limitations on command line length. Max argv size is defined by sysctl kern.argmax. It's at least 256K these days. I don't think it was ever as low as 1024. Most archive tools have an option that tells them to read file-lists from stdin, one pathname per line. If the archive format doesn't have to be pkzip, then consider using tar and gzip. You could hard-link selected files into a temp-folder rather than copying them. Then unlink when you're done and no copies needed. You can't hard-link symlinks, though, so that may not work. However, pkzip has no encoding for symlinks, so you can't zip a symlink, anyway. Or are you using ditto to write the zip file? -- GG ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Question about zipping files
Hi, I have a need to zip a selection of files from a folder. Sometimes the number of files may be in the hundreds, and sometimes some of the files may be multiple gigabytes in size. I need them to be referenced from a specific base folder in the hierarchy. Deployment is 10.5+ From what I can see, the following are my options: 1. Use NSTask to create a zip file, passing in as arguments all the filenames to zip. My question about this would be whether I would run into any restrictions with the length of the command which well be beyond the old 1024 character limits (not sure if any command line argument limits are still extant). I would think this would be the most efficient way to do it (both time and memory/storage wise), so long as there are no limitations on command line length. 2. Use NSTask to create a zip file, and then other tasks to add the files progressively. Concerned that this may be slow, and also the documentation says zip copies the files to a temporary folder and recreates the zip every time - probably not a good idea for a big zip and/or one with lots of files. 3. Use an NSTask to create a zip file of the entire folder, and then use other NSTasks to remove unwanted files. Probably won't be more than a few dozen each time, but I'm not sure whether it also unzips the file behind the scenes, or anything like that. Also it may unnecessarily be compressing a multi-GB file or two, which is inefficient. 4. Use the Omni zip framework to accomplish the task. As far as I can see, it appears to load all the files into memory in order to create the zip, so may not be a good idea when working with GB size files. Also the lack of documentation or examples makes it a little more work to understand it. 5. Copy all the files I want in my zip to a temp folder using NSFileManager, and then use NSTask to zip the folder. Downside, that it may take quite a while to copy the files, and of course you have the extra disk space used. Are there any other options that I'm not aware of? Which option would be the best to go with? Advice would be most welcome. Thx Gideon___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Question about zipping files
Gideon King (gid...@novamind.com) on 2010-02-15 00:28 said: Hi, I have a need to zip a selection of files from a folder. ... Are there any other options that I'm not aware of? NSWorkspaceCompressOperation? Sounds promising, right? But the docs say This operation always returns an error? HA! :) Did you investigate Scripting Bridge, AppleScript, or Apple Events? The Finder has a Compress option in its File menu, maybe you can tell Finder to zip for you. Stay away from NSTask when you can. Sean -- Patriotism is supporting your country all the time, and your government when it deserves it. - Mark Twain ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Question about zipping files
On Feb 14, 2010, at 9:28 PM, Gideon King wrote: 1. Use NSTask to create a zip file, passing in as arguments all the filenames to zip. My question about this would be whether I would run into any restrictions with the length of the command which well be beyond the old 1024 character limits (not sure if any command line argument limits are still extant). There is no 'command line' with NSTask (or with the execv system call it uses.) You pass an array of individual arguments that end up as the new process's argv[] array. There are no size limits that I know of. Note that this also means there is no need to encode characters in filesystem paths, even spaces and quotes, since they're not getting parsed by any shell. —Jens___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Question about zipping files
Thanks for the suggestion. Have not encountered Scripting Bridge before and have very little experience or understanding of AppleScript and no knowledge of Apple Events or what they do. I had a vague notion that Apple Events were pretty much old technology from before OSX, but now I see that it appears that it's the foundation of AppleScript. I guess I should take time to look into these technologies sometime (I come from a NextStep/OpenStep/WebObjects background)... Is there any particular reason you say to stay away from NSTask? Scripting Bridge seems like an interesting option, but after having generated the headers for Finder, I could not see a command there for compressing files. I guess it's not scriptable. Jens has confirmed that there is no limit to the length of the args for NSTask, so am planning to go with my option 1 - it's a technology I understand, and should apparently do what I need to do, and do it efficiently. On 15/02/2010, at 4:06 PM, Sean McBride wrote: Gideon King (gid...@novamind.com) on 2010-02-15 00:28 said: Hi, I have a need to zip a selection of files from a folder. ... Are there any other options that I'm not aware of? NSWorkspaceCompressOperation? Sounds promising, right? But the docs say This operation always returns an error? HA! :) Did you investigate Scripting Bridge, AppleScript, or Apple Events? The Finder has a Compress option in its File menu, maybe you can tell Finder to zip for you. Stay away from NSTask when you can. Sean -- Patriotism is supporting your country all the time, and your government when it deserves it. - Mark Twain ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Question about zipping files
1. Use NSTask to create a zip file, passing in as arguments all the filenames to zip. My question about this would be whether I would run into any restrictions with the length of the command which well be beyond the old 1024 character limits (not sure if any command line argument limits are still extant). I would think this would be the most efficient way to do it (both time and memory/storage wise), so long as there are no limitations on command line length. *Which option would be the best to go with?* I would recommend the first one. Create an array of selected files and pass those to NSTask. Advice would be most welcome. Thx Gideon___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/cocoa.learner%40gmail.com This email sent to cocoa.lear...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com