Migration Guide : Migrating from Version 9.0 : EsCompressionStreamsApp changes
EsCompressionStreamsApp changes
Reason for change
The EsCompressionStreamsApp was significantly overhauled and improved in 9.1, both in functionality and uniformity of the API. In order to achieve these improvements and make compression streams pluggable with other streams within VA Smalltalk, some API changes had to be made. For most simple usages of these streams, there will be very little change that the user will have to make.
Action required
ZipWriteStream
Before 9.1, a ZipWriteStream was a simple builder objects for a filesystem based MZZipArchive. A ‘nextPut’ type of API was used to add file paths to the zip file.
The new ZipWriteStream will actually write a valid zip archive to an underlying stream which it decorates. The stream it decorates could be memory, file or socket based. The ‘nextPut’ API has the more traditional meaning of adding byte/char content to the stream.
If all you need is the original behavior of adding string path names to an existing zip file archive on disk…it is easiest just to follow what the ZipWriteStream did internally.
 
| archive |
“From ZipWriteStream class>>on:”
archive := MZZipArchive basicNew filePath: aFilename; yourself.
“From ZipWriteStream>>nextPutAll:”
archive zipFiles: filenames
“From ZipWriteStream>>close”
archive close.

The equivalent of this in the streaming fashion is now:
 
| archive |
 
archive := ZipWriteStream on: (CfsWriteFileStream openEmpty: aFilename).
filenames do: [:filename |
archive
nextPutEntry: (ZipEntry named: filename);
nextPutAll: ‘Content of ‘, filename].
archive close.
 
ZipReadStream
ZipReadStreams have been changed in a similar way. Before 9.1, a ZipReadStream was a simple wrapper around an MZZipArchive. It was mostly used to facilitate unzipping file paths but did not have a streaming interface.
The new ZipReadStream will stream across zip entries from a zip archive that might be in memory, on the filesystem, or from a socket. It offers the full streaming API.
If all you need is the original behavior of opening up a filesystem path and unzipping file paths to some directory…this was accomplished by
 
| archive |

“From ZipReadStream class>>on:”
archive := MZZipArchive basicNew openRead: aFilename; yourself.
“From ZipReadStream>>contentsTo:”
archive contentsTo: aPath
“From ZipReadStream>>close”
archive close.
 
The equivalent of this in the new streaming fashion is now:

| archive |

archive := ZipReadStream on: (CfsReadFileStream on: aFilename).
[archive nextEntry notNil] whileTrue: [:entry | | out |
out := CfsWriteFileStream openEmpty: archive entry name.
out nextPutAll: archive upToEnd; close].
archive close.

Deflate/Gzip Streams
As of 9.1, all new compression streams have a unified API and one that should be familiar. The old versions of these streams used APIs like #read and #write. Additionally, #next would answer -1 as a signal for end of stream. In general, it was not possible to wrap other streams whose complete size was not known. This means sockets streams could not be used.
Now, their API is what you would expect from a stream…#next, #nextPut:, #nextPutAll:. #next will throw an exception if there is no more input, but #tryNext will answer nil instead. The API is a superset of all streams in the standard VAST system. These streams are meant to wrap any other stream in the system, which means you should expect to work with them just like any other stream in the system.
It’s not encouraged to use the old API, but for clarity their translations will be given below.
 
Old API
Translation
InflateReadStream>>available
Removed…use atEnd for determining if done instead of a byte count
InflateReadStream>>count
Removed…not used and can’t be determined in true streams.
InflateReadStream>>length
Removed…not used and can’t be determined in true streams.
InflateReadStream>> read: aByteArray
Use #tryNext: aByteArray
InflateReadStream>>read:atOffset:length:
Use #tryNext:into:startingAt:
InflateReadStream>>next
Use #tryNext but test for nil instead of -1
DeflateWriteStream>>write:atOffset:length
Use #nextPutAll:
 
 
Last modified date: 03/03/2020