[Q] About compressing

Lic. Edgar J. De Cleene edgardec2001 at yahoo.com.ar
Thu May 26 09:23:20 UTC 2005


Lex Spoon puso en su mail :

> 
> Hmm, here's some code that seems to work.
> 
> outputStream _ RWBinaryOrTextStream on: ''.
> zipper _ GZipWriteStream on: outputStream.
> zipper nextPutAll: 'hello, world!'.
> 
> zipper close.
> zipped _ outputStream contents.
> 
> 
> This achieves a marvelous "compression" ratio of 33/13 = 254%.  :)
> 
> To decode it:
> 
> inputStream _ RWBinaryOrTextStream with: zipped.
> inputStream reset.
> unzipper _ GZipReadStream on: inputStream.
> unzipper upToEnd asString
> 
> Note that there is a trick here in that you have to reset the
> RWBinaryOrTextStream after creating it -- the stream's position starts
> out at the end of the data instead of the beginning.  That trips me up
> all the time.
> 
> I hope this helps,
> 
> Lex
> 
Lex:

Sure helps, very compleete and  nice,


Yours is what I looking for (and fail). here what I find

I copy from somewhere and adapt to ChangeSet.

'From Squeak3.8 of ''5 May 2005'' [latest update: #6662] on 24 May 2005 at
10:50:47 am'!

!ChangeSet methodsFor: 'method changes' stamp: 'edc 5/24/2005 10:13'!
fileOutCompressed

    | compressBuffer compressStream data compressedStream compressTarget
fileStream |


    "Prepare the gzipped data"
    data _ WriteStream on: String new.
    data header; timeStamp.
    self fileOutPreambleOn: data.
    self fileOutOn: data.
    self fileOutPostscriptOn: data.
    data trailer.
    data _ ReadStream on: data contents.
    compressBuffer _ ByteArray new: 1000.
    compressStream _ GZipWriteStream on: (compressTarget _ WriteStream on:
(ByteArray new: 1000)).
    [data atEnd]
        whileFalse: [compressStream nextPutAll: (data nextInto:
compressBuffer)].
    compressStream close.
    compressedStream _ ReadStream on: compressTarget contents asString.

    fileStream _ FileStream newFileNamed: name, '.cs.gz'.
    fileStream fileOutClass: nil andObject: compressedStream.
fileStream close! !

And for compressed morphs

'From Squeak3.8 of ''5 May 2005'' [latest update: #6662] on 16 May 2005 at
11:42:41 am'!

!GZipReadStream class methodsFor: 'fileIn/Out' stamp: 'edc 5/16/2005 11:41'!
fileInCompresedMorph: fullFileName
    "FileIn the contents of a gzipped morph "
    | zipped unzipped loadedObject |
    zipped := self on: (FileStream readOnlyFileNamed: fullFileName).
    unzipped := MultiByteBinaryOrTextStream with: (zipped contents
asString).
    unzipped reset.
    loadedObject := unzipped fileInObjectAndCode.
loadedObject openInHand
! !


So , next question.
As ratio of microprocessor speed vs external extorage is bigger now what in
'96 when Squeak starts, why not have a fileOutCompressed method at Object
level what all system could use and avoid many duplicate code ?

Again , very, very thanks

Edgar



		
___________________________________ 
A tu celular ¿no le falta algo? 
Usá Yahoo! Messenger y Correo Yahoo! en tu teléfono celular. 
Más información en http://movil.yahoo.com.ar



More information about the Squeak-dev mailing list