compressing multiple files in Pharo

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

compressing multiple files in Pharo


I'm trying to help a friend with her non-profit website. She needs to be able to bundle files into a single file for easy downloading (and easy unpacking on the client). The files are pre-compressed sound files so further compression isn't really needed or useful.

My first attempt used ZipArchive, which seemed to write ok, but I can't decompress it. (I tried to describe that problem in another email.)

I'm now trying to compress more than one file to a GZipWriteStream. I copied and modified the code in the compressed method on FileStream to look like this:

"Write a new file that has the data in files compressed in GZip format."
| zipped buffer file dir |
dir := self directoryFor: 'hgo' language: 'arabic'.
zipped := dir newFileNamed: ('foobar', FileDirectory dot, 'gz').
zipped binary; setFileTypeToObject.
zipped := GZipWriteStream on: zipped.
dir fileNames do: [:fName |
file := FileStream fileNamed: fName.
file readOnly; binary.
buffer := ByteArray new: 50000.
[file atEnd] whileFalse: [
zipped nextPutAll: (file nextInto: buffer)].
file close.].
zipped close.

It doesn't work. It seems to compress the first file ok, but the others aren't included. 

Is there a reliable way in Pharo to solve the underlying problem of packing multiple binaries into a single file?

thanks much.