Prof A Olowofoyeku (The African Chief) wrote:
Frank Heckenbach wrote:
I suggest to link to the existing C libraries (libz and/or libpng). I don't generally recommend translating standard libraries to Pascal. The C libraries are tested by more people and (usually) maintained, and writing a Pascal interface is much easier than translating the whole library (especially if only a small part of the library interface is actually needed, like in many cases I know).
In principle, yes. However, the problem that I find is that many of the existing C libraries contain mainly low level stuff (at least, to me). Eike's zlib unit is an excellent interface to the C library, but I find that I am struggling to use it to decompress a compressed file, or to create one.
What I personally find helpful are high level functions, built on top of the interface units, so that, for example, I can "BlockRead" from a file to a buffer, pass that buffer to a high level (de)compression routine, retrieve the processed data in another buffer, and "BlockWrite" that to a file, or do whatever with it. PasZlib provides this kind of facility, which is why I decided to use it. But of course, it won't compile under GPC.
Perhaps Eike could provide some high level functions if he has the time?
e.g.,
- zlib_compress (inbuf, outbuf : pointer; insize, outsize : cardinal;
Var result : cardinal);
- zlib_decompress (inbuf, outbuf : pointer; insize, outsize :
cardinal; Var result : cardinal);
The fuctions `Compress' and `Uncompress' look quite similar. Note, though, that `DestLen: PuLongF' might better be `var DestLen: Cardinal' (unless Eike hass changed this already in a newer version than what I have here). Then DestLen takes the role of `outsize' on input and `result' on output, the rest is basically the same.
Then one can do something like; while not eof (infile) do begin blockread (infile, infbuf^, sizeof (infbuf^), bRead); zlib_compress (infbuf, outbuf, bRead, sizeof (outbuf^), compsize); blockwrite (outfile, outbuf^, compsize, bWritten); end;
Or perhaps I am just underestimating how difficult it would be to write such high level functions ...
If you want to read/write gzip (compatible) files (with headers, rather than jsut compressed blocks of data, IIUIC) there are the gz... routines which also seem rather easy to use.
Frank