Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
(#18) Added implementation of decompress
Browse files Browse the repository at this point in the history
Published basic decompress() function. Next in the line is to publish
the actual functions that are needed for compression/decompression
support of files.
  • Loading branch information
leandor committed Nov 6, 2016
1 parent 45c2037 commit 33f867b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/papi/lz4/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,25 @@ py::bytes lz4::compress(const py::bytes& buffer)

return py::bytes(dest.data(), res);
};

py::bytes lz4::decompress(const py::bytes& buffer, int expectedSize)
{
if (expectedSize < 0) {
throw std::exception("Argument out of valid range: 'expectedSize' was negative.");
}

if (expectedSize == 0) {
expectedSize = 16*1024;
}

std::string source{buffer};
std::vector<char> dest(expectedSize);

auto res = api::decompress_safe(source, dest);
if (res <= 0) {
const auto errorMsg = (format("decompression failed with code: %1%") % res).str();
throw std::exception(errorMsg.c_str());
}

return py::bytes(dest.data(), res);
};
1 change: 1 addition & 0 deletions src/papi/lz4/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ namespace lz4 {


py::bytes compress(const py::bytes& buffer);
py::bytes decompress(const py::bytes& buffer, int expectedSize = 0);
};
#endif // __CINT_LZ4_MODULE__

0 comments on commit 33f867b

Please sign in to comment.