[fpc-pascal] How to use TCompressionStream?

Michael Van Canneyt michael at freepascal.org
Sat Jun 21 19:48:43 CEST 2008



On Sat, 21 Jun 2008, Felipe Monteiro de Carvalho wrote:

> On Sat, Jun 21, 2008 at 2:27 PM, Michael Van Canneyt
> <michael at freepascal.org> wrote:
> > Call Compressor.flush first, only then all data will be in dest.
> > This is done automatically when it is destroyed:
> 
> There is no Compressor.Flush. But freeing it seams to work.

Copy & paste from zstream: 


        Tcompressionstream=class(Tcustomzlibstream)
        protected
          raw_written,compressed_written:longint;
        public
          constructor create(level:Tcompressionlevel;
                             dest:Tstream;
                             Askipheader:boolean=false);
          destructor destroy;override;
          function write(const buffer;count:longint):longint;override;
          procedure flush; //// <-------------------- Flush ?
          function get_compressionrate:single;
        end;


> 
> Now I am having trouble using TDecompressor. Should I use CopyFrom
> from another stream to get the decompressed data? This crashes the
> app. Also, CopyFrom expects the size, but I have no size ... I just
> want everything!

You cannot use CopyFrom.
You must do a read till there is no data anymore. 
See TStrings.LoadFromStream for instance.

Michael.



More information about the fpc-pascal mailing list