diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2020-07-11 23:40:49 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-07-14 13:56:36 +0000 |
commit | 592851fb67cd15807109d6f65fb81f6af89af966 (patch) | |
tree | 500c2246b6ae93bfe589fa45ded1f2788c8c7f8e /src/libutil/serialise.hh | |
parent | 9de96ef7d409fedea092045c4dbae7177f88962a (diff) |
LocalStore::addToStoreFromDump copy in chunks
Rather than copying byte-by-byte, we let the coroutine know how much
data we would like it to send back to us.
Diffstat (limited to 'src/libutil/serialise.hh')
-rw-r--r-- | src/libutil/serialise.hh | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh index 8386a4991..6cb9d1bf5 100644 --- a/src/libutil/serialise.hh +++ b/src/libutil/serialise.hh @@ -260,11 +260,20 @@ struct LambdaSource : Source /* Convert a function that feeds data into a Sink into a Source. The Source executes the function as a coroutine. */ std::unique_ptr<Source> sinkToSource( - std::function<void(Sink &)> fun, + std::function<void(Sink &, size_t &)> fun, std::function<void()> eof = []() { throw EndOfFile("coroutine has finished"); }); +static inline std::unique_ptr<Source> sinkToSource( + std::function<void(Sink &)> fun, + std::function<void()> eof = []() { + throw EndOfFile("coroutine has finished"); + }) +{ + return sinkToSource([fun](Sink & s, size_t & _) { fun(s); }, eof); +} + void writePadding(size_t len, Sink & sink); void writeString(const unsigned char * buf, size_t len, Sink & sink); |