Dec 192017
 
C and ASM code for LZW & deflate file compression.
File LZPIPE.ZIP from The Programmer’s Corner in
Category C Source Code
C and ASM code for LZW & deflate file compression.
File Name File Size Zip Size Zip Type
BITS.C 2879 1133 deflated
COMPRESS.C 12747 4433 deflated
CRC32.C 4371 1928 deflated
CRC32.H 222 126 deflated
DEFLATE.C 30282 8851 deflated
DISZIP.C 37356 11296 deflated
DOGZIP.PRJ 408 142 deflated
DOZ.C 3899 1281 deflated
DOZ.PRJ 128 71 deflated
DZMAIN.C 3701 1088 deflated
LZERROR.C 389 222 deflated
LZPIPE.H 1680 598 deflated
LZWBITS.H 3753 1393 deflated
LZWHEAD.H 224 144 deflated
MAKEFILE 971 359 deflated
MAKEFILE.386 1043 385 deflated
MAKEFILE.TCC 1376 484 deflated
MATCH.ASM 7880 2464 deflated
MATCH.S 13929 3603 deflated
MODERN.H 1532 483 deflated
OSCODE.H 902 420 deflated
READ.ME 7538 2795 deflated
README.OLD 1348 716 deflated
STDINC.H 277 173 deflated
TREES.C 39407 10779 deflated
UNLZW.C 8690 2862 deflated
ZALLOC.H 1596 691 deflated
ZIPDEFS.H 1040 522 deflated
ZIPGUTS.H 2638 977 deflated
ZIPPIPE.C 7993 2526 deflated

Download File LZPIPE.ZIP Here

Contents of the READ.ME file


This directory contains source codes for 'lzpipe' library, which
implements two most popular compression methods: LZW and deflate.
Both of these methods are de-facto lossless compression standards;
LZW is used in well-known 'compress' utility and deflate is used
by number of utilities starting from 'pkzip' by PKWare Inc. to,
let's say, 'gzip' utility.

The library was intended to give a programming capability
analogous to UNIX pipes for systems like MS-DOS, but it also
allows access to compressed files as well. In comparison to all
compression sources I've ever seen, this library allows to process
compressed data in open()/read()/write()/close() style.

These source codes implement pure compression, I made no attempt
to approach zip directory service.

Source codes for both LZW compression and decompression are
derived from sources of 'compress' utility initially written by
Joe Orost.

Source codes for deflate compression and inflate decompression are
derived from Info-Zip zip/unzip utilities sources. 'Inflate'
decompressor was initially written by Mark Adler and 'deflate'
compressor was initially written by Jean-loup Gailly.

Keep in mind that unlike LZW, deflate implementation development
is still continued and this library may be obsoleted by future
versions of Info-Zip software and/or gzip utility.

Info-ZIP's software (Zip, UnZip and related utilities) is free and
can be obtained as source code or executables from various
anonymous-ftp sites, including ftp.uu.net:/pub/archiving/zip/*.

All the codes must work in same fashion under most existing
operating systems; I tested them under MS-DOS and FreeBSD.

This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Copyright issues

1) All the decompression codes are in the public domain.

2) LZW compression code is in the public domain as well, but keep
in mind that LZW compression method is protected by US patent.
This partially means you can not sell inside US a product using
LZW compression (until you have patent owner permittion).

3) Since deflate compression code was borrowed from Info-Zip
distribution it is commited to Info-Zip license, which
in paticular says:
"Permission is granted to any individual or institution to use, copy, or
redistribute this software so long as all of the original files are included,
that it is not sold for profit, and that this copyright notice is retained."

and

"Q.Can I use the source code of zip and unzip in my commercial application?

A. Yes, so long as you include in your product an acknowledgment and an
offer of the original compression sources for free or for a small
copying fee, and make clear that there are no extra or hidden charges
resulting from the use of the compression code by your product. In other
words, you are allowed to sell only your own work, not ours."

See Info-Zip distribution for more details.


Well, now let's speak about sources itself. Here is very short
library description (all the definitions below are contained in
'lzpipe.h' header file):

Zip file format arguments:
#define ZIP_ANY 0
#define ZIP_PKW 1
#define ZIP_GNU 2

Value to indicate unpredictable data size for LZW
compression:
#define LZW_ANYSIZE 0x7fffffffL

Error code and corresponding messages list:
extern int lzerror;
extern char *lzerrlist[];

Individual error codes:
#define ZNOPEN 0
#define ZNOMEM 1 /* Not enough memory */
#define ZMAGIC 2 /* Bad magic header */
#define ZUNSUP 3 /* Reserved field or compression method */
#define ZHDEOF 4 /* EOF while processing header */
#define ZMOULD 5 /* Invalid compressed data */
#define ZNOEOF 6 /* More data to process at close */
#define ZBADSZ 7 /* Real size differs from recorded */
#define BADCRC 8 /* It is */
#define ZWRITE 9 /* Error writing output file */
#define ZERROR 10 /* Generic/internal error */

If no other said, the functions below return 0 on success
or -1 on error and place corresponding value into 'lzerror'
variable:

int unzalloc (void) - allocates a memory for inflate
decompression; as a rule you have not call this function.

int unzopen (LZ_INP_TYPE, int) - initialise inflation process
first argument may by file or function pointer depending
on compilation options.

int unzread (char *, unsigned) - read given number of
decompressed data into given buffer; returns number of
bytes read.

int unzclose (void) - terminates inflate processing; return
value above zero indicates warning message.

void unzfree (void) - as a rule you have not call this function.

int zipalloc (void) - allocates a memory for deflate
compression; as a rule you have not call this function.

int zipcreat (LZ_OUT_TYPE, int, int) - initialise deflation
process; first argument may be file or function pointer
depending on compilation options, second and third
arguments stands for zip file format (see above) and
compression level (1-9).

int zipwrite (char *, unsigned) - writes given number of bytes
from given buffer, returns number of bytes accepted.

void zipfree (void) - as a rule you have not call this function.

long zipclose (void) - terminates deflation process; returns total
size of compressed file or -1 on error.

int lzwalloc (int) - allocates memory for LZW compression with
bits factor not greater than given; returns maximum
possible bits factor.

int lzwcreat (LZ_OUT_TYPE, long, int) - initialise compression
process; first argument may by file or function pointer
depending on compilation options, second and third
arguments stands for uncompressed data size and bits
factor value.

int lzwwrite (char *, unsigned) - writes given number of bytes
from given buffer, returns number of bytes accepted.


void lzwfree (void) - as a rule you have not call this function.

long lzwclose (void) - terminates deflation process; returns total
size of compressed file or -1 on error.

int lzwmark (int) - allocates memory for LZW decompression with
bits factor not greater than given; returns maximum
possible bits factor.

int lzwopen (LZ_INP_TYPE) - initialises decompression process;
the argument may by file or function pointer depending on
compilation options.

int lzwread (char *, unsigned) - reads given number of
decompressed data into given buffer; returns number of
bytes read.

void lzwrelease (void) - frees decompression buffers.

The source directory also includes 'makefile' for UNIX and
'makefile.tcc' for Turbo C 2.01 under MS-DOS to build demo
programs: doz and dogzip. Both of them may be called as

do -c|d

where 'c' or 'd' options stand for compression and decompression
respectively.
Programs also have internal help, wich mention other options.

The compilation default is for pipe capability, use -DLZFILE
compilation option to biuld file access version.

If you have questions concerning this library please E-mail to

Tim V.Shaporev [email protected] aka
[email protected]


 December 19, 2017  Add comments

Leave a Reply