[fpc-devel] zstream, fpc and lazarus

Daniël Mantione daniel.mantione at freepascal.org
Sun Dec 2 09:10:49 CET 2007



Op Sun, 2 Dec 2007, schreef Paul Ishenin:

> Vincent Snijders wrote:
> > Daniël Mantione schreef:
> > > 
> > > Op Sat, 1 Dec 2007, schreef Vincent Snijders:
> > > 
> > > > Daniël Mantione schreef:
> > > > > If committed a proper fix, as bonus you can now randomly seek
> > > > > through the
> > > > > compressed file, there are no limitations anymore.
> > > > > 
> > > > Unfortunately, it still crashes Lazarus:
> > > > [FORMS.PP] ExceptionOccurred
> > > > Sender=Ecompressionerror
> > > 
> > > > Exception=buffer error
> > > 
> > > A buffer error occurs when the output buffer is full or the input
> > > buffer is empty. As the output buffer is set on each read operation
> > > it has to be the input buffer.
> > > 
> > > Put a:
> > > 
> > > writeln(Fstream.avail_in);
> > > 
> > > ... at the end of the reset procedure. If it happens to be non-zero,
> > > we have found the problem.
> > > 
> > 
> > It does not happen at all. The reset method doesn't seem to be called.
> I think the problem is still the same. When you seek TDecompressionStream to
> offset 0 with soFromBegining origin then Source stream must be repositioned
> too.

Ok, read with me. If we seek backwards (which is the case with offset 0 
from beginning), we call reset:

      if origin=sofrombeginning then
        dec(offset,raw_read);
      if offset<0 then
        begin
          inc(offset,raw_read);
          reset;
        end;

Inside reset, we set the source stream position to 0:

procedure Tdecompressionstream.reset;

var err:smallint;

begin
  raw_read:=0;
  compressed_read:=0;
  source.position:=0;
  inflateEnd(Fstream);
  if skipheader then
    err:=inflateInit2(Fstream,-MAX_WBITS)
  else
    err:=inflateInit(Fstream);
  if err<>Z_OK then
    raise Edecompressionerror.create(zerror(err));
end;

So, this is not the problem. I can't see any seek instruction inside 
fpreadpng.pp, so no seeking happens at all. There must be something 
different going on.

Daniël


More information about the fpc-devel mailing list