19573673dSchristos /* blast.h -- interface for blast.c 2fc4f4269Schristos Copyright (C) 2003, 2012, 2013 Mark Adler 3fc4f4269Schristos version 1.3, 24 Aug 2013 49573673dSchristos 59573673dSchristos This software is provided 'as-is', without any express or implied 69573673dSchristos warranty. In no event will the author be held liable for any damages 79573673dSchristos arising from the use of this software. 89573673dSchristos 99573673dSchristos Permission is granted to anyone to use this software for any purpose, 109573673dSchristos including commercial applications, and to alter it and redistribute it 119573673dSchristos freely, subject to the following restrictions: 129573673dSchristos 139573673dSchristos 1. The origin of this software must not be misrepresented; you must not 149573673dSchristos claim that you wrote the original software. If you use this software 159573673dSchristos in a product, an acknowledgment in the product documentation would be 169573673dSchristos appreciated but is not required. 179573673dSchristos 2. Altered source versions must be plainly marked as such, and must not be 189573673dSchristos misrepresented as being the original software. 199573673dSchristos 3. This notice may not be removed or altered from any source distribution. 209573673dSchristos 219573673dSchristos Mark Adler madler@alumni.caltech.edu 229573673dSchristos */ 239573673dSchristos 249573673dSchristos 259573673dSchristos /* 269573673dSchristos * blast() decompresses the PKWare Data Compression Library (DCL) compressed 279573673dSchristos * format. It provides the same functionality as the explode() function in 289573673dSchristos * that library. (Note: PKWare overused the "implode" verb, and the format 299573673dSchristos * used by their library implode() function is completely different and 309573673dSchristos * incompatible with the implode compression method supported by PKZIP.) 318cbf5cb7Schristos * 328cbf5cb7Schristos * The binary mode for stdio functions should be used to assure that the 338cbf5cb7Schristos * compressed data is not corrupted when read or written. For example: 348cbf5cb7Schristos * fopen(..., "rb") and fopen(..., "wb"). 359573673dSchristos */ 369573673dSchristos 379573673dSchristos 389573673dSchristos typedef unsigned (*blast_in)(void *how, unsigned char **buf); 399573673dSchristos typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len); 409573673dSchristos /* Definitions for input/output functions passed to blast(). See below for 419573673dSchristos * what the provided functions need to do. 429573673dSchristos */ 439573673dSchristos 449573673dSchristos 45fc4f4269Schristos int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow, 46fc4f4269Schristos unsigned *left, unsigned char **in); 479573673dSchristos /* Decompress input to output using the provided infun() and outfun() calls. 489573673dSchristos * On success, the return value of blast() is zero. If there is an error in 499573673dSchristos * the source data, i.e. it is not in the proper format, then a negative value 509573673dSchristos * is returned. If there is not enough input available or there is not enough 519573673dSchristos * output space, then a positive error is returned. 529573673dSchristos * 539573673dSchristos * The input function is invoked: len = infun(how, &buf), where buf is set by 549573673dSchristos * infun() to point to the input buffer, and infun() returns the number of 559573673dSchristos * available bytes there. If infun() returns zero, then blast() returns with 569573673dSchristos * an input error. (blast() only asks for input if it needs it.) inhow is for 579573673dSchristos * use by the application to pass an input descriptor to infun(), if desired. 589573673dSchristos * 59fc4f4269Schristos * If left and in are not NULL and *left is not zero when blast() is called, 60*4f645668Schristos * then the *left bytes at *in are consumed for input before infun() is used. 61fc4f4269Schristos * 629573673dSchristos * The output function is invoked: err = outfun(how, buf, len), where the bytes 639573673dSchristos * to be written are buf[0..len-1]. If err is not zero, then blast() returns 649573673dSchristos * with an output error. outfun() is always called with len <= 4096. outhow 659573673dSchristos * is for use by the application to pass an output descriptor to outfun(), if 669573673dSchristos * desired. 679573673dSchristos * 68fc4f4269Schristos * If there is any unused input, *left is set to the number of bytes that were 69fc4f4269Schristos * read and *in points to them. Otherwise *left is set to zero and *in is set 70fc4f4269Schristos * to NULL. If left or in are NULL, then they are not set. 71fc4f4269Schristos * 729573673dSchristos * The return codes are: 739573673dSchristos * 749573673dSchristos * 2: ran out of input before completing decompression 759573673dSchristos * 1: output error before completing decompression 769573673dSchristos * 0: successful decompression 779573673dSchristos * -1: literal flag not zero or one 789573673dSchristos * -2: dictionary size not in 4..6 799573673dSchristos * -3: distance is too far back 809573673dSchristos * 819573673dSchristos * At the bottom of blast.c is an example program that uses blast() that can be 829573673dSchristos * compiled to produce a command-line decompression filter by defining TEST. 839573673dSchristos */ 84