mirror of
https://github.com/NixOS/nix.git
synced 2025-12-04 16:10:59 +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
|
|
@ -1,4 +1,5 @@
|
|||
#include "nix/util/serialise.hh"
|
||||
#include "nix/util/compression.hh"
|
||||
#include "nix/util/signals.hh"
|
||||
#include "nix/util/util.hh"
|
||||
|
||||
|
|
@ -252,6 +253,19 @@ void StringSource::skip(size_t len)
|
|||
pos += len;
|
||||
}
|
||||
|
||||
CompressedSource::CompressedSource(RestartableSource & source, const std::string & compressionMethod)
|
||||
: compressedData([&]() {
|
||||
StringSink sink;
|
||||
auto compressionSink = makeCompressionSink(compressionMethod, sink);
|
||||
source.drainInto(*compressionSink);
|
||||
compressionSink->finish();
|
||||
return std::move(sink.s);
|
||||
}())
|
||||
, compressionMethod(compressionMethod)
|
||||
, stringSource(compressedData)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
|
||||
{
|
||||
struct SourceToSink : FinishSink
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue