libutil: allow draining Generator<Bytes> into sinks
Change-Id: I442d03a5399096d4baca9a2618b4c4b64db36c4b
This commit is contained in:
parent
4857feb910
commit
b252b3c6e3
2 changed files with 10 additions and 0 deletions
|
@ -65,5 +65,6 @@ if cxx.get_linker_id() in ['ld.bfd', 'ld.gold']
|
|||
endif
|
||||
|
||||
libstore = dependency('lixstore', 'lix-store', required : true)
|
||||
libutil = dependency('lixutil', 'lix-util', required : true)
|
||||
|
||||
subdir('lib/Nix')
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#pragma once
|
||||
///@file
|
||||
|
||||
#include <concepts>
|
||||
#include <memory>
|
||||
|
||||
#include "generator.hh"
|
||||
#include "strings.hh"
|
||||
#include "types.hh"
|
||||
#include "file-descriptor.hh"
|
||||
|
@ -340,6 +342,13 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun);
|
|||
*/
|
||||
std::unique_ptr<Source> sinkToSource(std::function<void(Sink &)> fun);
|
||||
|
||||
inline Sink & operator<<(Sink & sink, Generator<Bytes> && g)
|
||||
{
|
||||
while (auto buffer = g.next()) {
|
||||
sink(std::string_view(buffer->data(), buffer->size()));
|
||||
}
|
||||
return sink;
|
||||
}
|
||||
|
||||
void writePadding(size_t len, Sink & sink);
|
||||
void writeString(std::string_view s, Sink & sink);
|
||||
|
|
Loading…
Reference in a new issue