Page 1 of 1

Bug or misunderstanding

Posted: Tue Apr 11, 2006 11:17 pm
by Paul van der Eijk
Madshi,

Trying to use compress / uncompress; the versions with two pointers.
When I do compress --> uncompress the uncompressed buffer contains
the correct data but the uncompress function returns 0. How do I get
the uncompressed length? I expected uncompress to return that value.
See code below what I try to do:

--Paul

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

uses
  sysutils,
  madzip;

const
   bufsrc = 100;
   bufdest = 120;
var
   psrc, pdest: pbytearray;
   n, nl: integer;
begin
GetMem(psrc, bufsrc);
for n := 0 to bufsrc - 1
do psrc^[n] := n mod 4;
GetMem(pdest, bufdest);
nl := madzip.Compress(psrc, pdest, bufsrc, bufdest);
WriteLn('nl = ', nl);
for n := 0 to bufsrc - 1
do psrc^[n] := 0;
n := madZip.Uncompress(pdest, psrc, bufsrc, bufdest);
WriteLn('n = ', n);
for n := 0 to bufsrc - 1
do if psrc[n] <> n mod 4
   then
      WriteLn('Error, n = ', n, ' value = ', psrc[n], ' expected ', n mod 4);
end.

Posted: Wed Apr 12, 2006 9:55 am
by madshi
In the Uncompress call shouldn't the "buffer size" parameters be swapped?

Posted: Wed Apr 12, 2006 4:16 pm
by Paul van der Eijk
Madshi,

I made that correction but no difference.

--Paul

Posted: Wed Apr 12, 2006 4:21 pm
by madshi
Wait a moment, when calling "Uncompress" the uncompressor of course needs to know how much data the compressed stream has. So the 3rd parameter has to be what "Compress" returned. Both "bufsrc" and "bufdest" are incorrect.

Posted: Wed Apr 12, 2006 4:38 pm
by Paul van der Eijk
Yes, I found that too a minute ago by stepping through the code.
Doing so, I think there could be a problem in line 3607; my change
(z.TotalInput = dword(srcLen)) and (z.TotalOutput <= dword(dstLen)) then //!!

Output size should be less/equal to capcatity, not equal??

--Paul

Posted: Wed Apr 12, 2006 5:52 pm
by madshi
No, it must be equal. Why should the uncompressed data be shorter than the original data? That doesn't make any sense.

Posted: Wed Apr 12, 2006 6:14 pm
by Paul van der Eijk
Madshi,

Respectfully disagree.

I have two buffers, original data and compressed data. Compressed data goes to a file, preceeded with the length of the compressed data. But I do not always write the the same amount of uncompressed data. So when reading the data back, I know that my buffer of uncompressed data is large enough, but it will not always fill to capacity.

--Paul

Posted: Wed Apr 12, 2006 6:16 pm
by madshi
Ok, but you do know how long the original data was? You can use a bigger buffer, if you like, but why not giving in the size of the original data?

Posted: Mon Apr 24, 2006 6:16 pm
by Paul van der Eijk
The original design (ZLib) does not need to know the uncompressed
length. The uncompress function returns an indication that there was not enough memory. This function takes a var parameter which is length of output buffer allocated, on returns the length of the uncompressed data.

No big deal, but I wanted to stay with my original design not to write the ucompressed length to the file.

--Paul

Posted: Wed Apr 26, 2006 7:56 am
by madshi
Well, I guess I could relax the length checking.