mirror of
https://github.com/NixOS/nix.git
synced 2025-11-19 00:39:37 +01:00
refactor(libutil): add CompressedSource
Introduce a `CompressedSource` class in libutil's `serialise.hh` that compresses a `RestartableSource` and owns the compressed data. This is a general-purpose utility that can be used anywhere compressed data needs to be treated as a source.
This commit is contained in:
parent
bffbdcfddc
commit
93fe3354b5
3 changed files with 61 additions and 9 deletions
|
|
@ -141,18 +141,12 @@ void HttpBinaryCacheStore::upsertFile(
|
|||
req.method = HttpMethod::PUT;
|
||||
auto compressionMethod = getCompressionMethod(path);
|
||||
|
||||
std::string data;
|
||||
std::optional<StringSource> stringSource{};
|
||||
std::optional<CompressedSource> compressed;
|
||||
|
||||
if (compressionMethod) {
|
||||
StringSink sink{};
|
||||
auto compressionSink = makeCompressionSink(*compressionMethod, sink);
|
||||
source.drainInto(*compressionSink);
|
||||
compressionSink->finish();
|
||||
data = std::move(sink.s);
|
||||
compressed = CompressedSource(source, *compressionMethod);
|
||||
req.headers.emplace_back("Content-Encoding", *compressionMethod);
|
||||
stringSource = StringSource{data};
|
||||
req.data = {*stringSource};
|
||||
req.data = {compressed->size(), *compressed};
|
||||
} else {
|
||||
req.data = {sizeHint, source};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue