compress/decompress on OS X

Richard Gaskin ambassador at fourthworld.com
Tue Nov 9 11:36:41 EST 2004


Frank Engel wrote:
> Why bother with using gzip on the file?  Compress the data before 
> putting it into the custom properties (see the 'compress' function).  
> This eliminates yet another external dependency  (yes, I know that the 
> compression ratio will be slightly less, but the resulting code will be 
> more portable, and not rely on having the user install gzip manually, or 
> need to deal with tracking it externally...)
> 
> Of course, you could also try reading the stack file back as binary data 
> and run compress() on that, but it would be somewhat messier.
> 
> It would also require more than the size of the file(s) to be compressed 
> as temporary space on the drive:
> 
> The size of the files, in the form of the original files.
> The size of the files, in the custom properties.
> More space (less than the size of the files), in the gzipped version of 
> the file.
> 
> You could help to further reduce this by deleting the temporary stack 
> file before writing out the compressed version...
> 
> 
> Also, I would recommend a custom property set rather than using the 
> properties directly; this should help to avoid name conflicts (if a file 
> has the name of an internal Rev property, such as a file named 
> "foregroundColor" -- you never know).
> 
> So then something like this (plus error checking code, etc.):
> 
> on archiveFile intoStack, fileName
>   put compress(URL ("binfile:" & fileName)) into the dataFork[fileName] 
> of intoStack
>   put compress(URL ("resfile:" & fileName)) into the 
> resourceFork[fileName] of intoStack
> end archiveFile
> 
> on extractFile fromStack, nameInArchive, fileNameToCreate
>   put decompress(the dataFork[nameInArchive] of fromStack) into URL 
> ("binfile:" & fileNameToCreate)
>   put decompress(the resourceFork[nameInArchive] of fromStack) into URL 
> ("resfile:" & fileNameToCreate)
> end extractFile
> 

Good stuff.

You may also add a third loop which stores the type and creator code, 
obtained from the last item of "the detailed files".

-- 
  Richard Gaskin
  Fourth World Media Corporation
  ___________________________________________________________
  Ambassador at FourthWorld.com       http://www.FourthWorld.com


More information about the use-livecode mailing list