zstd.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include <util/generic/ptr.h>
  3. #include <util/stream/input.h>
  4. #include <util/stream/output.h>
  5. /**
  6. * @addtogroup Streams_Archs
  7. * @{
  8. */
  9. // @brief Stream to compress into zstd archive
  10. class TZstdCompress: public IOutputStream {
  11. public:
  12. /**
  13. @param slave stream to write compressed data to
  14. @param quality, higher quality - slower but better compression.
  15. 0 is default compression (see constant ZSTD_CLEVEL_DEFAULT(3))
  16. max compression is ZSTD_MAX_CLEVEL (22)
  17. */
  18. explicit TZstdCompress(IOutputStream* slave, int quality = 0);
  19. ~TZstdCompress() override;
  20. private:
  21. void DoWrite(const void* buffer, size_t size) override;
  22. void DoFlush() override;
  23. void DoFinish() override;
  24. public:
  25. class TImpl;
  26. THolder<TImpl> Impl_;
  27. };
  28. ////////////////////////////////////////////////////////////////////////////////
  29. // @brief Buffered stream to decompress from zstd archive
  30. class TZstdDecompress: public IInputStream {
  31. public:
  32. /**
  33. @param slave stream to read compressed data from
  34. @param bufferSize approximate size of buffer compressed data is read in
  35. */
  36. explicit TZstdDecompress(IInputStream* slave, size_t bufferSize = 8 * 1024);
  37. ~TZstdDecompress() override;
  38. private:
  39. size_t DoRead(void* buffer, size_t size) override;
  40. private:
  41. class TImpl;
  42. THolder<TImpl> Impl_;
  43. };
  44. /** @} */