lzma.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Core part of LZMA deflate algorithm, in a form that can be used
  2. for embedding into various tools that need native lz support.
  3. The caller supplies input (src) and output (dst) buffers in the
  4. structure below. The LZMA code then proceedes to advance srcptr
  5. and dstptr as it reads the input and produces output. Once either
  6. of those pointers exceeds respective high-water marks (srchwm or
  7. dsthwm), lzma_inflate() returns LZMA_NEED_INPUT or LZMA_NEED_OUTPUT
  8. to the caller which is then expected to read/flush the data,
  9. update the pointers and call lzma_inflate() again.
  10. LZMA code can and will overshot hwm-s, by several bytes in case of
  11. input and by up to ~300 bytes for output. This is expected. The areas
  12. between hwn and end pointers allow for soft-braking the algorithm,
  13. making it restartable without much impact on the performance.
  14. The caller should aim at having around a PAGE between respective hwm
  15. and end pointers prior to any lzma_inflate() call.
  16. Hitting either of the end pointers is a hard non-recoverable error
  17. indicated by LZMA_INPUT_OVER or LZMA_OUTPUT_OVER. Getting those codes
  18. means the process cannot be restarted anymore.
  19. LZMA streams typically contain back-references, which in this setup
  20. would be counted back from dstptr. It is up to the caller to figure
  21. out dictsize for the stream, and keep at least that much decoded data
  22. in memory between dstbuf and dstptr when flushing output.
  23. Any back-reference past dstbuf causes LZMA_INVALID_REF return which
  24. is not recoverable.
  25. The private[] part of the structure is pretty involved and does not
  26. need to be exposed to the caller. See `struct private` in lzma.c.
  27. It is, however, must be kept intact between calls to lzma_inflate()
  28. through a continuous input stream. The caller is expected to reserve
  29. a buffer of at least LZMA_SIZE, and use lzma_create() to turn that
  30. into a usable `struct lzma`. */
  31. #define LZMA_SIZE 30000
  32. #define LZMA_STREAM_END 1
  33. #define LZMA_NEED_INPUT 2
  34. #define LZMA_NEED_OUTPUT 3
  35. #define LZMA_OUTPUT_OVER 4
  36. #define LZMA_INPUT_OVER 5
  37. #define LZMA_INVALID_REF 6
  38. #define LZMA_RANGE_CHECK 7
  39. struct lzma {
  40. void* srcbuf;
  41. void* srcptr;
  42. void* srchwm;
  43. void* srcend;
  44. void* dstbuf;
  45. void* dstptr;
  46. void* dsthwm;
  47. void* dstend;
  48. byte private[];
  49. };
  50. struct lzma* lzma_create(void* buf, int len);
  51. int lzma_inflate(struct lzma* lz);