20 content_.push_back(onelheoutput);
30 compressedContent_.emplace_back(initialSize);
31 std::vector<uint8_t> &
output = compressedContent_.back();
37 const unsigned int threshsize = 32*1024*1024;
41 lzma_stream strm = LZMA_STREAM_INIT;
42 lzma_ret ret = lzma_easy_encoder(&strm, preset, LZMA_CHECK_CRC64);
44 lzma_action
action = LZMA_RUN;
46 strm.next_in =
reinterpret_cast<uint8_t*
>(&inbuf[0]);
48 strm.next_out = output.data();
49 strm.avail_out = output.size();
51 unsigned int compressedSize = 0;
53 while (ret==LZMA_OK) {
55 if (strm.avail_in == 0 && !input.eof()) {
56 input.read(inbuf, bufsize);
57 strm.next_in =
reinterpret_cast<uint8_t*
>(&inbuf[0]);
58 strm.avail_in = input.gcount();
66 ret = lzma_code(&strm, action);
69 compressedSize = output.size() - strm.avail_out;
72 if (strm.avail_out == 0 && ret==LZMA_OK) {
73 unsigned int oldsize = output.size();
74 if (oldsize<threshsize) {
75 output.resize(2*oldsize);
78 output.resize(oldsize + threshsize);
80 strm.next_out = &output[oldsize];
81 strm.avail_out = output.size() - oldsize;
88 if (ret!=LZMA_STREAM_END) {
90 <<
"There was a failure in LZMA compression in LHEXMLStringProduct.";
94 output.resize(compressedSize);
101 lzma_stream strm = LZMA_STREAM_INIT;
102 lzma_ret ret = lzma_stream_decoder(&strm, UINT64_MAX, LZMA_CONCATENATED);
104 lzma_action
action = LZMA_FINISH;
108 char outbuf[bufsize];
110 const std::vector<uint8_t> &
input = compressedContent_[
i];
112 strm.next_in = input.data();
113 strm.avail_in = input.size();
114 strm.next_out =
reinterpret_cast<uint8_t*
>(&outbuf[0]);
115 strm.avail_out = bufsize;
117 while (ret==LZMA_OK) {
119 ret = lzma_code(&strm, action);
122 output.write(outbuf,bufsize-strm.avail_out);
125 if (strm.avail_out==0 && ret==LZMA_OK) {
126 strm.next_out =
reinterpret_cast<uint8_t*
>(&outbuf[0]);
127 strm.avail_out = bufsize;
133 if (ret!=LZMA_STREAM_END) {
135 <<
"There was a failure in LZMA decompression in LHEXMLStringProduct.";
void swap(LHEXMLStringProduct &other)
const std::vector< std::string > & getStrings() const
static std::string const input
const std::vector< std::vector< uint8_t > > & getCompressed() const
virtual ~LHEXMLStringProduct()
std::vector< std::vector< uint8_t > > compressedContent_
std::vector< std::string > content_
void writeCompressedContent(std::ostream &output, unsigned int i) const
bool mergeProduct(LHEXMLStringProduct const &other)
void fillCompressedContent(std::istream &input, unsigned int initialSize=4 *1024 *1024)