kusano fc6ab3
/* blast.h -- interface for blast.c
kusano fc6ab3
  Copyright (C) 2003, 2012 Mark Adler
kusano fc6ab3
  version 1.2, 24 Oct 2012
kusano fc6ab3
kusano fc6ab3
  This software is provided 'as-is', without any express or implied
kusano fc6ab3
  warranty.  In no event will the author be held liable for any damages
kusano fc6ab3
  arising from the use of this software.
kusano fc6ab3
kusano fc6ab3
  Permission is granted to anyone to use this software for any purpose,
kusano fc6ab3
  including commercial applications, and to alter it and redistribute it
kusano fc6ab3
  freely, subject to the following restrictions:
kusano fc6ab3
kusano fc6ab3
  1. The origin of this software must not be misrepresented; you must not
kusano fc6ab3
     claim that you wrote the original software. If you use this software
kusano fc6ab3
     in a product, an acknowledgment in the product documentation would be
kusano fc6ab3
     appreciated but is not required.
kusano fc6ab3
  2. Altered source versions must be plainly marked as such, and must not be
kusano fc6ab3
     misrepresented as being the original software.
kusano fc6ab3
  3. This notice may not be removed or altered from any source distribution.
kusano fc6ab3
kusano fc6ab3
  Mark Adler    madler@alumni.caltech.edu
kusano fc6ab3
 */
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
/*
kusano fc6ab3
 * blast() decompresses the PKWare Data Compression Library (DCL) compressed
kusano fc6ab3
 * format.  It provides the same functionality as the explode() function in
kusano fc6ab3
 * that library.  (Note: PKWare overused the "implode" verb, and the format
kusano fc6ab3
 * used by their library implode() function is completely different and
kusano fc6ab3
 * incompatible with the implode compression method supported by PKZIP.)
kusano fc6ab3
 *
kusano fc6ab3
 * The binary mode for stdio functions should be used to assure that the
kusano fc6ab3
 * compressed data is not corrupted when read or written.  For example:
kusano fc6ab3
 * fopen(..., "rb") and fopen(..., "wb").
kusano fc6ab3
 */
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
typedef unsigned (*blast_in)(void *how, unsigned char **buf);
kusano fc6ab3
typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len);
kusano fc6ab3
/* Definitions for input/output functions passed to blast().  See below for
kusano fc6ab3
 * what the provided functions need to do.
kusano fc6ab3
 */
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow);
kusano fc6ab3
/* Decompress input to output using the provided infun() and outfun() calls.
kusano fc6ab3
 * On success, the return value of blast() is zero.  If there is an error in
kusano fc6ab3
 * the source data, i.e. it is not in the proper format, then a negative value
kusano fc6ab3
 * is returned.  If there is not enough input available or there is not enough
kusano fc6ab3
 * output space, then a positive error is returned.
kusano fc6ab3
 *
kusano fc6ab3
 * The input function is invoked: len = infun(how, &buf), where buf is set by
kusano fc6ab3
 * infun() to point to the input buffer, and infun() returns the number of
kusano fc6ab3
 * available bytes there.  If infun() returns zero, then blast() returns with
kusano fc6ab3
 * an input error.  (blast() only asks for input if it needs it.)  inhow is for
kusano fc6ab3
 * use by the application to pass an input descriptor to infun(), if desired.
kusano fc6ab3
 *
kusano fc6ab3
 * The output function is invoked: err = outfun(how, buf, len), where the bytes
kusano fc6ab3
 * to be written are buf[0..len-1].  If err is not zero, then blast() returns
kusano fc6ab3
 * with an output error.  outfun() is always called with len <= 4096.  outhow
kusano fc6ab3
 * is for use by the application to pass an output descriptor to outfun(), if
kusano fc6ab3
 * desired.
kusano fc6ab3
 *
kusano fc6ab3
 * The return codes are:
kusano fc6ab3
 *
kusano fc6ab3
 *   2:  ran out of input before completing decompression
kusano fc6ab3
 *   1:  output error before completing decompression
kusano fc6ab3
 *   0:  successful decompression
kusano fc6ab3
 *  -1:  literal flag not zero or one
kusano fc6ab3
 *  -2:  dictionary size not in 4..6
kusano fc6ab3
 *  -3:  distance is too far back
kusano fc6ab3
 *
kusano fc6ab3
 * At the bottom of blast.c is an example program that uses blast() that can be
kusano fc6ab3
 * compiled to produce a command-line decompression filter by defining TEST.
kusano fc6ab3
 */