You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
3.0 KiB

  1. /* -*- mode: C; c-basic-offset: 4 -*- */
  2. #ifndef TOKU_COMPRESS_H
  3. #define TOKU_COMPRESS_H
  4. #ident "$Id$"
  5. #include <zlib.h>
  6. #include <db.h>
  7. // The following provides an abstraction of quicklz and zlib.
  8. // We offer three compression methods: ZLIB, QUICKLZ, and LZMA, as well as a "no compression" option. These options are declared in make_tdb.c.
  9. // The resulting byte string includes enough information for us to decompress it. That is, we can tell whether it's z-compressed or qz-compressed or xz-compressed.
  10. size_t toku_compress_bound (enum toku_compression_method a, size_t size);
  11. // Effect: Return the number of bytes needed to compress a buffer of size SIZE using compression method A.
  12. // Typically, the result is a little bit larger than SIZE, since some data cannot be compressed.
  13. // Usage note: It may help to know roughly how much space is involved.
  14. // zlib's bound is something like (size + (size>>12) + (size>>14) + (size>>25) + 13.
  15. // quicklz's bound is something like size+400.
  16. void toku_compress (enum toku_compression_method a,
  17. // the following types and naming conventions come from zlib.h
  18. Bytef *dest, uLongf *destLen,
  19. const Bytef *source, uLong sourceLen);
  20. // Effect: Using compression method A, compress SOURCE into DEST. The number of bytes to compress is passed in SOURCELEN.
  21. // On input: *destLen is the size of the buffer.
  22. // On output: *destLen is the size of the actual compressed data.
  23. // Usage note: sourceLen may be be zero (unlike for quicklz, which requires sourceLen>0).
  24. // Requires: The buffer must be big enough to hold the compressed data. (That is *destLen >= compressBound(a, sourceLen))
  25. // Requires: sourceLen < 2^32.
  26. // Usage note: Although we *try* to assert if the DESTLEN isn't big enough, it's possible that it's too late by then (in the case of quicklz which offers
  27. // no way to avoid a buffer overrun.) So we require that that DESTLEN is big enough.
  28. // Rationale: zlib's argument order is DEST then SOURCE with the size of the buffer passed in *destLen, and the size of the result returned in *destLen.
  29. // quicklz's argument order is SOURCE then DEST with the size returned (and it has no way to verify that an overright didn't happen).
  30. // We use zlib's calling conventions partly because it is safer, and partly because it is more established.
  31. // We also use zlib's ugly camel case convention for destLen and sourceLen.
  32. // Unlike zlib, we return no error codes. Instead, we require that the data be OK and the size of the buffers is OK, and assert if there's a problem.
  33. void toku_decompress (Bytef *dest, uLongf destLen,
  34. const Bytef *source, uLongf sourceLen);
  35. // Effect: Decompress source (length sourceLen) into dest (length destLen)
  36. // This function can decompress data compressed with either zlib or quicklz compression methods (calling toku_compress(), which puts an appropriate header on so we know which it is.)
  37. // Requires: destLen is equal to the actual decompressed size of the data.
  38. // Requires: The source must have been properly compressed.
  39. #endif