1212397c6Schristos /* blast.h -- interface for blast.c 2796c32c9Schristos Copyright (C) 2003, 2012, 2013 Mark Adler 3796c32c9Schristos version 1.3, 24 Aug 2013 4212397c6Schristos 5212397c6Schristos This software is provided 'as-is', without any express or implied 6212397c6Schristos warranty. In no event will the author be held liable for any damages 7212397c6Schristos arising from the use of this software. 8212397c6Schristos 9212397c6Schristos Permission is granted to anyone to use this software for any purpose, 10212397c6Schristos including commercial applications, and to alter it and redistribute it 11212397c6Schristos freely, subject to the following restrictions: 12212397c6Schristos 13212397c6Schristos 1. The origin of this software must not be misrepresented; you must not 14212397c6Schristos claim that you wrote the original software. If you use this software 15212397c6Schristos in a product, an acknowledgment in the product documentation would be 16212397c6Schristos appreciated but is not required. 17212397c6Schristos 2. Altered source versions must be plainly marked as such, and must not be 18212397c6Schristos misrepresented as being the original software. 19212397c6Schristos 3. This notice may not be removed or altered from any source distribution. 20212397c6Schristos 21212397c6Schristos Mark Adler madler@alumni.caltech.edu 22212397c6Schristos */ 23212397c6Schristos 24212397c6Schristos 25212397c6Schristos /* 26212397c6Schristos * blast() decompresses the PKWare Data Compression Library (DCL) compressed 27212397c6Schristos * format. It provides the same functionality as the explode() function in 28212397c6Schristos * that library. (Note: PKWare overused the "implode" verb, and the format 29212397c6Schristos * used by their library implode() function is completely different and 30212397c6Schristos * incompatible with the implode compression method supported by PKZIP.) 31ba340e45Schristos * 32ba340e45Schristos * The binary mode for stdio functions should be used to assure that the 33ba340e45Schristos * compressed data is not corrupted when read or written. For example: 34ba340e45Schristos * fopen(..., "rb") and fopen(..., "wb"). 35212397c6Schristos */ 36212397c6Schristos 37212397c6Schristos 38212397c6Schristos typedef unsigned (*blast_in)(void *how, unsigned char **buf); 39212397c6Schristos typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len); 40212397c6Schristos /* Definitions for input/output functions passed to blast(). See below for 41212397c6Schristos * what the provided functions need to do. 42212397c6Schristos */ 43212397c6Schristos 44212397c6Schristos 45796c32c9Schristos int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow, 46796c32c9Schristos unsigned *left, unsigned char **in); 47212397c6Schristos /* Decompress input to output using the provided infun() and outfun() calls. 48212397c6Schristos * On success, the return value of blast() is zero. If there is an error in 49212397c6Schristos * the source data, i.e. it is not in the proper format, then a negative value 50212397c6Schristos * is returned. If there is not enough input available or there is not enough 51212397c6Schristos * output space, then a positive error is returned. 52212397c6Schristos * 53212397c6Schristos * The input function is invoked: len = infun(how, &buf), where buf is set by 54212397c6Schristos * infun() to point to the input buffer, and infun() returns the number of 55212397c6Schristos * available bytes there. If infun() returns zero, then blast() returns with 56212397c6Schristos * an input error. (blast() only asks for input if it needs it.) inhow is for 57212397c6Schristos * use by the application to pass an input descriptor to infun(), if desired. 58212397c6Schristos * 59796c32c9Schristos * If left and in are not NULL and *left is not zero when blast() is called, 60*4b169a6bSchristos * then the *left bytes at *in are consumed for input before infun() is used. 61796c32c9Schristos * 62212397c6Schristos * The output function is invoked: err = outfun(how, buf, len), where the bytes 63212397c6Schristos * to be written are buf[0..len-1]. If err is not zero, then blast() returns 64212397c6Schristos * with an output error. outfun() is always called with len <= 4096. outhow 65212397c6Schristos * is for use by the application to pass an output descriptor to outfun(), if 66212397c6Schristos * desired. 67212397c6Schristos * 68796c32c9Schristos * If there is any unused input, *left is set to the number of bytes that were 69796c32c9Schristos * read and *in points to them. Otherwise *left is set to zero and *in is set 70796c32c9Schristos * to NULL. If left or in are NULL, then they are not set. 71796c32c9Schristos * 72212397c6Schristos * The return codes are: 73212397c6Schristos * 74212397c6Schristos * 2: ran out of input before completing decompression 75212397c6Schristos * 1: output error before completing decompression 76212397c6Schristos * 0: successful decompression 77212397c6Schristos * -1: literal flag not zero or one 78212397c6Schristos * -2: dictionary size not in 4..6 79212397c6Schristos * -3: distance is too far back 80212397c6Schristos * 81212397c6Schristos * At the bottom of blast.c is an example program that uses blast() that can be 82212397c6Schristos * compiled to produce a command-line decompression filter by defining TEST. 83212397c6Schristos */ 84