blast.h 3.4 KB

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