Home | History | Annotate | Line # | Download | only in blast
blast.h revision 1.3
      1  1.1  christos /* blast.h -- interface for blast.c
      2  1.3  christos   Copyright (C) 2003, 2012 Mark Adler
      3  1.3  christos   version 1.2, 24 Oct 2012
      4  1.1  christos 
      5  1.1  christos   This software is provided 'as-is', without any express or implied
      6  1.1  christos   warranty.  In no event will the author be held liable for any damages
      7  1.1  christos   arising from the use of this software.
      8  1.1  christos 
      9  1.1  christos   Permission is granted to anyone to use this software for any purpose,
     10  1.1  christos   including commercial applications, and to alter it and redistribute it
     11  1.1  christos   freely, subject to the following restrictions:
     12  1.1  christos 
     13  1.1  christos   1. The origin of this software must not be misrepresented; you must not
     14  1.1  christos      claim that you wrote the original software. If you use this software
     15  1.1  christos      in a product, an acknowledgment in the product documentation would be
     16  1.1  christos      appreciated but is not required.
     17  1.1  christos   2. Altered source versions must be plainly marked as such, and must not be
     18  1.1  christos      misrepresented as being the original software.
     19  1.1  christos   3. This notice may not be removed or altered from any source distribution.
     20  1.1  christos 
     21  1.1  christos   Mark Adler    madler (at) alumni.caltech.edu
     22  1.1  christos  */
     23  1.1  christos 
     24  1.1  christos 
     25  1.1  christos /*
     26  1.1  christos  * blast() decompresses the PKWare Data Compression Library (DCL) compressed
     27  1.1  christos  * format.  It provides the same functionality as the explode() function in
     28  1.1  christos  * that library.  (Note: PKWare overused the "implode" verb, and the format
     29  1.1  christos  * used by their library implode() function is completely different and
     30  1.1  christos  * incompatible with the implode compression method supported by PKZIP.)
     31  1.3  christos  *
     32  1.3  christos  * The binary mode for stdio functions should be used to assure that the
     33  1.3  christos  * compressed data is not corrupted when read or written.  For example:
     34  1.3  christos  * fopen(..., "rb") and fopen(..., "wb").
     35  1.1  christos  */
     36  1.1  christos 
     37  1.1  christos 
     38  1.1  christos typedef unsigned (*blast_in)(void *how, unsigned char **buf);
     39  1.1  christos typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len);
     40  1.1  christos /* Definitions for input/output functions passed to blast().  See below for
     41  1.1  christos  * what the provided functions need to do.
     42  1.1  christos  */
     43  1.1  christos 
     44  1.1  christos 
     45  1.1  christos int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow);
     46  1.1  christos /* Decompress input to output using the provided infun() and outfun() calls.
     47  1.1  christos  * On success, the return value of blast() is zero.  If there is an error in
     48  1.1  christos  * the source data, i.e. it is not in the proper format, then a negative value
     49  1.1  christos  * is returned.  If there is not enough input available or there is not enough
     50  1.1  christos  * output space, then a positive error is returned.
     51  1.1  christos  *
     52  1.1  christos  * The input function is invoked: len = infun(how, &buf), where buf is set by
     53  1.1  christos  * infun() to point to the input buffer, and infun() returns the number of
     54  1.1  christos  * available bytes there.  If infun() returns zero, then blast() returns with
     55  1.1  christos  * an input error.  (blast() only asks for input if it needs it.)  inhow is for
     56  1.1  christos  * use by the application to pass an input descriptor to infun(), if desired.
     57  1.1  christos  *
     58  1.1  christos  * The output function is invoked: err = outfun(how, buf, len), where the bytes
     59  1.1  christos  * to be written are buf[0..len-1].  If err is not zero, then blast() returns
     60  1.1  christos  * with an output error.  outfun() is always called with len <= 4096.  outhow
     61  1.1  christos  * is for use by the application to pass an output descriptor to outfun(), if
     62  1.1  christos  * desired.
     63  1.1  christos  *
     64  1.1  christos  * The return codes are:
     65  1.1  christos  *
     66  1.1  christos  *   2:  ran out of input before completing decompression
     67  1.1  christos  *   1:  output error before completing decompression
     68  1.1  christos  *   0:  successful decompression
     69  1.1  christos  *  -1:  literal flag not zero or one
     70  1.1  christos  *  -2:  dictionary size not in 4..6
     71  1.1  christos  *  -3:  distance is too far back
     72  1.1  christos  *
     73  1.1  christos  * At the bottom of blast.c is an example program that uses blast() that can be
     74  1.1  christos  * compiled to produce a command-line decompression filter by defining TEST.
     75  1.1  christos  */
     76