mirror of
https://github.com/NixOS/nix
synced 2025-06-25 23:11:16 +02:00
BinaryCacheStore: Support "none" compression method
This commit is contained in:
parent
8e065c6b3e
commit
5acb691402
5 changed files with 51 additions and 31 deletions
|
@ -15,7 +15,7 @@ struct LzmaStream
|
|||
lzma_stream & operator()() { return strm; }
|
||||
};
|
||||
|
||||
std::string compressXZ(const std::string & in)
|
||||
static ref<std::string> 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<std::string> res = make_ref<std::string>();
|
||||
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<std::string> decompressXZ(const std::string & in)
|
||||
static ref<std::string> decompressXZ(const std::string & in)
|
||||
{
|
||||
LzmaStream strm;
|
||||
|
||||
|
@ -95,4 +95,24 @@ ref<std::string> decompressXZ(const std::string & in)
|
|||
}
|
||||
}
|
||||
|
||||
ref<std::string> compress(const std::string & method, ref<std::string> in)
|
||||
{
|
||||
if (method == "none")
|
||||
return in;
|
||||
else if (method == "xz")
|
||||
return compressXZ(*in);
|
||||
else
|
||||
throw UnknownCompressionMethod(format("unknown compression method ‘%s’") % method);
|
||||
}
|
||||
|
||||
ref<std::string> decompress(const std::string & method, ref<std::string> in)
|
||||
{
|
||||
if (method == "none")
|
||||
return in;
|
||||
else if (method == "xz")
|
||||
return decompressXZ(*in);
|
||||
else
|
||||
throw UnknownCompressionMethod(format("unknown compression method ‘%s’") % method);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue