From 5acb6914020a94be8468d7670b564388c59794ee Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 29 Apr 2016 17:02:57 +0200 Subject: BinaryCacheStore: Support "none" compression method --- src/libutil/compression.cc | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/libutil/compression.cc') diff --git a/src/libutil/compression.cc b/src/libutil/compression.cc index beede13211fa..e8a820d30429 100644 --- a/src/libutil/compression.cc +++ b/src/libutil/compression.cc @@ -15,7 +15,7 @@ struct LzmaStream lzma_stream & operator()() { return strm; } }; -std::string compressXZ(const std::string & in) +static ref compressXZ(const std::string & in) { LzmaStream strm; @@ -28,7 +28,7 @@ std::string compressXZ(const std::string & in) lzma_action action = LZMA_RUN; uint8_t outbuf[BUFSIZ]; - string res; + ref res = make_ref(); strm().next_in = (uint8_t *) in.c_str(); strm().avail_in = in.size(); strm().next_out = outbuf; @@ -43,7 +43,7 @@ std::string compressXZ(const std::string & in) lzma_ret ret = lzma_code(&strm(), action); if (strm().avail_out == 0 || ret == LZMA_STREAM_END) { - res.append((char *) outbuf, sizeof(outbuf) - strm().avail_out); + res->append((char *) outbuf, sizeof(outbuf) - strm().avail_out); strm().next_out = outbuf; strm().avail_out = sizeof(outbuf); } @@ -56,7 +56,7 @@ std::string compressXZ(const std::string & in) } } -ref decompressXZ(const std::string & in) +static ref decompressXZ(const std::string & in) { LzmaStream strm; @@ -95,4 +95,24 @@ ref decompressXZ(const std::string & in) } } +ref compress(const std::string & method, ref in) +{ + if (method == "none") + return in; + else if (method == "xz") + return compressXZ(*in); + else + throw UnknownCompressionMethod(format("unknown compression method ā€˜%sā€™") % method); +} + +ref decompress(const std::string & method, ref in) +{ + if (method == "none") + return in; + else if (method == "xz") + return decompressXZ(*in); + else + throw UnknownCompressionMethod(format("unknown compression method ā€˜%sā€™") % method); +} + } -- cgit 1.4.1