[fpc-pascal] TStream descendant to compress/decompress gzip data from another stream

Michalis Kamburelis michalis.kambi at gmail.com
Wed Mar 27 19:22:57 CET 2013


Hi,

Like the subject says, I'm looking for a TStream implementation that 
takes another TStream and compresses/decompresses data in gzip format. I 
would like to read/write gzip data to a stream, any TStream (maybe 
TFileStream, maybe TMemoryStream, maybe a stream from the network like 
TSocketStream, etc.).

One would think that the ZStream unit will contain something like that, 
but it does not. ZStream has:

- TCompressionStream and TDecompressionStream, but they use the "deflate 
format", which is different than "gzip format" (gzip format at least 
adds some headers around). So you can't use them to directly read/write 
data from a xxx.gz file.

- TGZFileStream, which does use the desired "gzip format"... but it can 
only read local files (constructor takes just a FileName parameter). It 
cannot read from/to another stream.

Is there a stream class that satisfies both these conditions 
simultaneously (uses "gzip format" and can read/write to another TStream)?

Offtopic: I probably would avoid the ZStream unit anyway, as it uses 
PasZLib, which is a Pascal rewrite of the old zlib code. I would prefer 
to rather use ZLib unit (that links to a Zlib library, usually in 
so/dll/dylib) instead. Reasons are security (the C zlib library is 
probably more maintained than gory internals of paszlib) and because I 
have to distribute Zlib library anyway (libpng depends on it, and I use 
libpng).

Google found an old thread on lazarus mailing list about this ("FPC, 
gzip and stream") but without any solution, everything mentioned there 
has either the limitations of TCompressionStream/TDecompressionStream 
(no gzip format) or TGZFileStream (not able to work wit ObjectPascal 
streams).

Thanks in advance for answers,
Michalis



More information about the fpc-pascal mailing list