I use paszlib library, in zCompres unit is
function compress2 (dest : Pbyte;
var destLen : cardinal;
const source : array of byte;
sourceLen : cardinal;
level : integer) : integer;
var
stream : z_stream;
err : integer;
begin
stream.next_in := Pbyte(@source);
stream.avail_in := cardinal(sourceLen);
stream.next_out := dest;
stream.avail_out := cardinal(destLen);
.....
err := deflateInit(stream, level);
.....
err := deflate(stream, Z_FINISH);
if (err <> Z_STREAM_END) then
begin
deflateEnd(stream);
if err = Z_OK then
compress2 := Z_BUF_ERROR
else
compress2 := err;
exit;
end;
destLen := stream.total_out;
err := deflateEnd(stream);
compress2 := err;
end;
This compress one block at once, how to use TStream and compress/uncompress chunk by chunk. Unit gzIO has streaming but works on files given by path, I prefer TStream and maybe memory streams.
Is sggzip.pas but is not compatible with paszlib.
I want write method: at first it must deflateInit, at end deflateEnd, and in loop deflate(stream, ?); where "?" is not Z_FINISH and maybe one from list below:
Z_NO_FLUSH = 0;
Z_PARTIAL_FLUSH = 1;
Z_SYNC_FLUSH = 2;
Z_FULL_FLUSH = 3;
Z_FINISH = 4;