diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2018-03-21 22:56:02 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2018-03-21 23:10:40 +0100 |
commit | 47f7e5585bbb9a6acfaddda7327ba4eeb5b662c2 (patch) | |
tree | 9ef9057da8d91c8178f54161841bcc76d52ab7c1 /src/libutil/archive.cc | |
parent | 92dfc223272083061d0c02d35efcad0a8bb9ba4d (diff) |
Make 'nix copy --from ssh://...' run in constant memory
For instance, this reduced the memory consumption of
$ nix copy --from ssh://localhost --to ~/my-nix /nix/store/1n7x0yv8vq6zi90hfmian84vdhd04bgp-blender-2.79a
from 632 MiB to 16 MiB.
Diffstat (limited to 'src/libutil/archive.cc')
-rw-r--r-- | src/libutil/archive.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libutil/archive.cc b/src/libutil/archive.cc index f71229d8f..a1d9d3233 100644 --- a/src/libutil/archive.cc +++ b/src/libutil/archive.cc @@ -350,4 +350,21 @@ void restorePath(const Path & path, Source & source) } +void copyNAR(Source & source, Sink & sink) +{ + // FIXME: if 'source' is the output of dumpPath() followed by EOF, + // we should just forward all data directly without parsing. + + ParseSink parseSink; /* null sink; just parse the NAR */ + + LambdaSource wrapper([&](unsigned char * data, size_t len) { + auto n = source.read(data, len); + sink(data, n); + return n; + }); + + parseDump(parseSink, wrapper); +} + + } |