feat(nix-compat/nar/reader): provide passthrough buffered I/O

Allow taking advantage of the buffer of the underlying reader to avoid
unnecessary copies of file data.

We can't easily implement the methods of BufRead directly, since we
have some extra I/O to perform in the final consume() invocation.

That could be resolved at the cost of additional bookkeeping, but this
will suffice for now.

Change-Id: I8100cf0abd79e7469670b8596bd989be5db44a91
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10089
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
edef 2023-11-19 06:56:03 +00:00
parent 785ff80c8b
commit a11abc02e2
2 changed files with 82 additions and 20 deletions

View file

@ -135,13 +135,13 @@ fn process_file_reader(
// write the blob.
let mut blob_writer = {
let mut dest = SyncIoBridge::new(blob_writer);
io::copy(&mut file_reader, &mut dest)?;
let mut dst = SyncIoBridge::new(blob_writer);
dest.shutdown()?;
file_reader.copy(&mut dst)?;
dst.shutdown()?;
// return back the blob_reader
dest.into_inner()
// return back the blob_writer
dst.into_inner()
};
// close the blob_writer, retrieve the digest.