S3BinaryCacheStore: Support compression of narinfo and log files

You can now set the store parameter "text-compression=br" to compress
textual files in the binary cache (i.e. narinfo and logs) using
Brotli. This sets the Content-Encoding header; the extension of
compressed files is unchanged.

You can separately specify the compression of log files using
"log-compression=br". This is useful when you don't want to compress
narinfo files for backward compatibility.
This commit is contained in:
Eelco Dolstra 2017-03-14 15:03:53 +01:00
parent 2691498b5c
commit 8b1d65bebe
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
5 changed files with 71 additions and 8 deletions

View file

@ -39,6 +39,16 @@ std::string resolveUri(const std::string & uri)
return uri;
}
ref<std::string> decodeContent(const std::string & encoding, ref<std::string> data)
{
if (encoding == "")
return data;
else if (encoding == "br")
return decompress(encoding, *data);
else
throw Error("unsupported Content-Encoding %s", encoding);
}
struct CurlDownloader : public Downloader
{
CURLM * curlm = 0;
@ -275,12 +285,8 @@ struct CurlDownloader : public Downloader
result.cached = httpStatus == 304;
done = true;
/* Ad hoc support for brotli, since curl doesn't do
this yet. */
try {
if (encoding == "br")
result.data = decompress("br", *result.data);
result.data = decodeContent(encoding, ref<std::string>(result.data));
callSuccess(success, failure, const_cast<const DownloadResult &>(result));
} catch (...) {
done = true;