Re: guess the file size of compressed file from the original
Re: guess the file size of compressed file from the original
- Subject: Re: guess the file size of compressed file from the original
- From: Graff <email@hidden>
- Date: Sat, 26 Jun 2004 23:38:09 -0400
On Jun 26, 2004, at 10:24 PM, Bill wrote:
What is the eventual purpose of doing this? Will you need to be able
to open each zip file individually or are you splitting them up and
then planning to re-join them before un-archiving them?
Well, let's start from the purpose: using Gmail as an "alternative
backup". Currently, I used a script to zip every file of a chosen
folder, then send them out as email attachment. Each email subject is
the path (Mac style) of the file, body is the backup time.
At this moment, I need to avoid file bigger than 5MB, pick them out by
hand, because my ISP limits each email must be smaller than 5MB.
My experience of Gmail is that their search engine is excellent ;)
Using file name or subfolder name, I get what I want to find.
Inspired by your idea, I'm thinking of making disk image of big file,
split it into 5MB segment, zip the segment. For small file, just zip
it. Or, to make disk image from the chosen folder, split it into 5MB
segment, and set the body of email to list of items contained.
No need to zip the segmented dmg. The shell tool hdiutil will compress
it for you. You don't even need to pull the files out seperately, you
can take a folder and put it straight into a dmg file with hdiutil.
There is also no need to just zip a small file, the dmg file will never
be much larger than the file and the file won't segment if its below
the segment size. The disk image solution should handle all of these
cases by itself.
Here's a little bit of code that takes the folder, puts it into a dmg,
compresses it to the maximum amount, segments it to the desktop and
then clears out the temporary file needed for the dmg creation:
----
set theFolder to choose folder
set posixFolder to quoted form of POSIX path of theFolder
set theName to name of (info for theFolder)
set tmpFolder to POSIX path of (path to "temp")
set tmpFile to quoted form of (tmpFolder & "tempArchive.dmg")
set dstPath to quoted form of ((POSIX path of (path to desktop folder))
& theName)
do shell script "/usr/bin/hdiutil create -ov -imagekey zlib-level=9
-srcfolder " & posixFolder & " -volname " & theName & " " & tmpFile
do shell script "/usr/bin/hdiutil segment -o " & dstPath & "
-segmentSize 5m " & tmpFile
do shell script "rm -f " & tmpFile
----
The segmented files will be named for the folder they came from and the
names will go like foldername.dmg, foldername.002.dmgpart,
foldername.003.dmgpart, and so on.
Once it creates the segments all you need to do to open the segmented
dmg file is to have all the segments in one place and then open the
first dmg - the one without a number and which ends in .dmg instead of
.dmgpart.
To explain the hdiutil commands a bit I'll break them down here:
the archive creation command:
hdiutil create -ov -imagekey zlib-level=9 -srcfolder
/path/to/source -volname theName /path/to/archive.dmg
run the hdiutil tool
hdiutil
create an archive
create
overwrite an old archive with the same name
-ov
set the compression to maximum
-imagekey zlib-level=9
use /path/to/source as the stuff to archive, this automatically sets
the size of the archive
-srcfolder /path/to/source
set the name of the volume - for when it is opened and appears as a disk
-volname theName
the destination of the archive file, as well as the name of the file
/path/to/archive.dmg
the segmenting command:
hdiutil segment -o /path/to/archive.dmg -segmentSize 5m
/path/to/destination/basename
run hdiutil
hdiutil
set the location and the base name of the segmented files
segment -o /path/to/destination/basename
set the max size of the segments to 5 MB
-segmentSize 5m
set the dmg file to segment
/path/to/archive.dmg
- Ken
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.