proxygen
proxygen::ZstdStreamDecompressor Class Reference

#include <ZstdStreamDecompressor.h>

Public Member Functions

 ZstdStreamDecompressor (size_t, std::string)
 
 ~ZstdStreamDecompressor ()
 
std::unique_ptr< folly::IOBufdecompress (const folly::IOBuf *in)
 
ZstdStatusType getStatus ()
 

Public Attributes

ZstdStatusType status_
 

Private Attributes

ZSTD_DStream * dStream_ {nullptr}
 
ZSTD_DDict * dDict_ {nullptr}
 
size_t totalLen_ {0}
 
size_t totalDec_ {0}
 

Detailed Description

Definition at line 37 of file ZstdStreamDecompressor.h.

Constructor & Destructor Documentation

ZstdStreamDecompressor::ZstdStreamDecompressor ( size_t  totalLen,
std::string  dictStr 
)
explicit

Definition at line 21 of file ZstdStreamDecompressor.cpp.

References dDict_, dStream_, proxygen::ERROR, and status_.

22  : totalLen_(totalLen) {
23  dStream_ = ZSTD_createDStream();
24  if (dictStr != "") {
25  dDict_ = ZSTD_createDDict(&dictStr, dictStr.length());
26  if (dStream_ == nullptr || dDict_ == nullptr ||
27  ZSTD_isError(ZSTD_initDStream_usingDDict(dStream_, dDict_))) {
29  }
30  } else {
31  if (dStream_ == nullptr ||
32  ZSTD_isError(ZSTD_initDStream(dStream_))) {
34  }
35  }
36 }
ZstdStreamDecompressor::~ZstdStreamDecompressor ( )

Definition at line 38 of file ZstdStreamDecompressor.cpp.

References dDict_, and dStream_.

38  {
39  if (dStream_) {
40  ZSTD_freeDStream(dStream_);
41  }
42  if (dDict_) {
43  ZSTD_freeDDict(dDict_);
44  }
45 }

Member Function Documentation

std::unique_ptr< folly::IOBuf > ZstdStreamDecompressor::decompress ( const folly::IOBuf in)

Definition at line 47 of file ZstdStreamDecompressor.cpp.

References proxygen::CONTINUE, folly::IOBuf::create(), dStream_, proxygen::ERROR, gmock_output_test::output, folly::gen::range(), status_, proxygen::SUCCESS, totalDec_, totalLen_, and uint8_t.

48  {
49  if (dStream_ == nullptr) {
51  return nullptr;
52  }
53 
54  auto out = folly::IOBuf::create(ZSTD_DStreamOutSize());
55 
56  size_t buffOutSize = ZSTD_DStreamOutSize();
57  std::unique_ptr<unsigned char[]> buffOut(new unsigned char[buffOutSize]);
58  auto appender = folly::io::Appender(out.get(), buffOutSize);
59 
60  for (const folly::ByteRange range : *in) {
61  ZSTD_inBuffer input = {range.data(), range.size(), 0};
62  while (input.pos < input.size) {
63  ZSTD_outBuffer output = {buffOut.get(), buffOutSize, 0};
64  size_t toRead = ZSTD_decompressStream(dStream_, &output, &input);
65 
66  if (ZSTD_isError(toRead)) {
68  return nullptr;
69  }
70 
71  if (toRead == 0) {
72  ZSTD_resetDStream(dStream_);
73  }
74 
75  if (output.pos > 0) {
76  size_t copied =
77  appender.pushAtMost((const uint8_t*)output.dst, output.pos);
78  CHECK(copied == output.pos);
79  }
80  totalDec_ += input.size;
81 
82  if (totalDec_ < totalLen_) {
84  } else if (totalDec_ > totalLen_) {
86  } else {
88  }
89  }
90  }
91 
92  return out;
93 }
static std::unique_ptr< IOBuf > create(std::size_t capacity)
Definition: IOBuf.cpp:229
Gen range(Value begin, Value end)
Definition: Base.h:467
ZstdStatusType proxygen::ZstdStreamDecompressor::getStatus ( )
inline

Definition at line 42 of file ZstdStreamDecompressor.h.

42 {return status_;};

Member Data Documentation

ZSTD_DDict* proxygen::ZstdStreamDecompressor::dDict_ {nullptr}
private

Definition at line 47 of file ZstdStreamDecompressor.h.

Referenced by ZstdStreamDecompressor(), and ~ZstdStreamDecompressor().

ZSTD_DStream* proxygen::ZstdStreamDecompressor::dStream_ {nullptr}
private
ZstdStatusType proxygen::ZstdStreamDecompressor::status_

Definition at line 42 of file ZstdStreamDecompressor.h.

Referenced by decompress(), and ZstdStreamDecompressor().

size_t proxygen::ZstdStreamDecompressor::totalDec_ {0}
private

Definition at line 49 of file ZstdStreamDecompressor.h.

Referenced by decompress().

size_t proxygen::ZstdStreamDecompressor::totalLen_ {0}
private

Definition at line 48 of file ZstdStreamDecompressor.h.

Referenced by decompress().


The documentation for this class was generated from the following files: