1275793eaSopenharmony_ci/* blast.h -- interface for blast.c 2275793eaSopenharmony_ci Copyright (C) 2003, 2012, 2013 Mark Adler 3275793eaSopenharmony_ci version 1.3, 24 Aug 2013 4275793eaSopenharmony_ci 5275793eaSopenharmony_ci This software is provided 'as-is', without any express or implied 6275793eaSopenharmony_ci warranty. In no event will the author be held liable for any damages 7275793eaSopenharmony_ci arising from the use of this software. 8275793eaSopenharmony_ci 9275793eaSopenharmony_ci Permission is granted to anyone to use this software for any purpose, 10275793eaSopenharmony_ci including commercial applications, and to alter it and redistribute it 11275793eaSopenharmony_ci freely, subject to the following restrictions: 12275793eaSopenharmony_ci 13275793eaSopenharmony_ci 1. The origin of this software must not be misrepresented; you must not 14275793eaSopenharmony_ci claim that you wrote the original software. If you use this software 15275793eaSopenharmony_ci in a product, an acknowledgment in the product documentation would be 16275793eaSopenharmony_ci appreciated but is not required. 17275793eaSopenharmony_ci 2. Altered source versions must be plainly marked as such, and must not be 18275793eaSopenharmony_ci misrepresented as being the original software. 19275793eaSopenharmony_ci 3. This notice may not be removed or altered from any source distribution. 20275793eaSopenharmony_ci 21275793eaSopenharmony_ci Mark Adler madler@alumni.caltech.edu 22275793eaSopenharmony_ci */ 23275793eaSopenharmony_ci 24275793eaSopenharmony_ci 25275793eaSopenharmony_ci/* 26275793eaSopenharmony_ci * blast() decompresses the PKWare Data Compression Library (DCL) compressed 27275793eaSopenharmony_ci * format. It provides the same functionality as the explode() function in 28275793eaSopenharmony_ci * that library. (Note: PKWare overused the "implode" verb, and the format 29275793eaSopenharmony_ci * used by their library implode() function is completely different and 30275793eaSopenharmony_ci * incompatible with the implode compression method supported by PKZIP.) 31275793eaSopenharmony_ci * 32275793eaSopenharmony_ci * The binary mode for stdio functions should be used to assure that the 33275793eaSopenharmony_ci * compressed data is not corrupted when read or written. For example: 34275793eaSopenharmony_ci * fopen(..., "rb") and fopen(..., "wb"). 35275793eaSopenharmony_ci */ 36275793eaSopenharmony_ci 37275793eaSopenharmony_ci 38275793eaSopenharmony_citypedef unsigned (*blast_in)(void *how, unsigned char **buf); 39275793eaSopenharmony_citypedef int (*blast_out)(void *how, unsigned char *buf, unsigned len); 40275793eaSopenharmony_ci/* Definitions for input/output functions passed to blast(). See below for 41275793eaSopenharmony_ci * what the provided functions need to do. 42275793eaSopenharmony_ci */ 43275793eaSopenharmony_ci 44275793eaSopenharmony_ci 45275793eaSopenharmony_ciint blast(blast_in infun, void *inhow, blast_out outfun, void *outhow, 46275793eaSopenharmony_ci unsigned *left, unsigned char **in); 47275793eaSopenharmony_ci/* Decompress input to output using the provided infun() and outfun() calls. 48275793eaSopenharmony_ci * On success, the return value of blast() is zero. If there is an error in 49275793eaSopenharmony_ci * the source data, i.e. it is not in the proper format, then a negative value 50275793eaSopenharmony_ci * is returned. If there is not enough input available or there is not enough 51275793eaSopenharmony_ci * output space, then a positive error is returned. 52275793eaSopenharmony_ci * 53275793eaSopenharmony_ci * The input function is invoked: len = infun(how, &buf), where buf is set by 54275793eaSopenharmony_ci * infun() to point to the input buffer, and infun() returns the number of 55275793eaSopenharmony_ci * available bytes there. If infun() returns zero, then blast() returns with 56275793eaSopenharmony_ci * an input error. (blast() only asks for input if it needs it.) inhow is for 57275793eaSopenharmony_ci * use by the application to pass an input descriptor to infun(), if desired. 58275793eaSopenharmony_ci * 59275793eaSopenharmony_ci * If left and in are not NULL and *left is not zero when blast() is called, 60275793eaSopenharmony_ci * then the *left bytes at *in are consumed for input before infun() is used. 61275793eaSopenharmony_ci * 62275793eaSopenharmony_ci * The output function is invoked: err = outfun(how, buf, len), where the bytes 63275793eaSopenharmony_ci * to be written are buf[0..len-1]. If err is not zero, then blast() returns 64275793eaSopenharmony_ci * with an output error. outfun() is always called with len <= 4096. outhow 65275793eaSopenharmony_ci * is for use by the application to pass an output descriptor to outfun(), if 66275793eaSopenharmony_ci * desired. 67275793eaSopenharmony_ci * 68275793eaSopenharmony_ci * If there is any unused input, *left is set to the number of bytes that were 69275793eaSopenharmony_ci * read and *in points to them. Otherwise *left is set to zero and *in is set 70275793eaSopenharmony_ci * to NULL. If left or in are NULL, then they are not set. 71275793eaSopenharmony_ci * 72275793eaSopenharmony_ci * The return codes are: 73275793eaSopenharmony_ci * 74275793eaSopenharmony_ci * 2: ran out of input before completing decompression 75275793eaSopenharmony_ci * 1: output error before completing decompression 76275793eaSopenharmony_ci * 0: successful decompression 77275793eaSopenharmony_ci * -1: literal flag not zero or one 78275793eaSopenharmony_ci * -2: dictionary size not in 4..6 79275793eaSopenharmony_ci * -3: distance is too far back 80275793eaSopenharmony_ci * 81275793eaSopenharmony_ci * At the bottom of blast.c is an example program that uses blast() that can be 82275793eaSopenharmony_ci * compiled to produce a command-line decompression filter by defining TEST. 83275793eaSopenharmony_ci */ 84