diff options
author | Florian Klink <flokli@flokli.de> | 2023-11-18T22·56+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-11-18T23·07+0000 |
commit | 8beb38b50c135991a15958716612463cc78b87ca (patch) | |
tree | 9b65d159cb0b5485adab75875850dda871517024 /tvix/store | |
parent | eda5d4da377913c015f6658abd5d0f2c1366db48 (diff) |
refactor(tvix/store/fs): simpllify read r/7030
We can just use take(size) to restrict reading to that as a max. Change-Id: I0fbda74e4fb98ffeababae86a325233416029acf Reviewed-on: https://cl.tvl.fyi/c/depot/+/10072 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/store')
-rw-r--r-- | tvix/store/src/fs/mod.rs | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/tvix/store/src/fs/mod.rs b/tvix/store/src/fs/mod.rs index ee0348c1ff73..f942cc962257 100644 --- a/tvix/store/src/fs/mod.rs +++ b/tvix/store/src/fs/mod.rs @@ -26,7 +26,7 @@ use std::{ time::Duration, }; use tokio::{ - io::{AsyncBufReadExt, AsyncSeekExt}, + io::{AsyncReadExt, AsyncSeekExt}, sync::mpsc, }; use tracing::{debug, info_span, instrument, warn}; @@ -614,24 +614,8 @@ impl FileSystem for TvixStoreFs { let mut buf: Vec<u8> = Vec::with_capacity(size as usize); - while (buf.len() as u64) < size as u64 { - let int_buf = blob_reader.fill_buf().await?; - // copy things from the internal buffer into buf to fill it till up until size - - // an empty buffer signals we reached EOF. - if int_buf.is_empty() { - break; - } - - // calculate how many bytes we can read from int_buf. - // It's either all of int_buf, or the number of bytes missing in buf to reach size. - let len_to_copy = std::cmp::min(int_buf.len(), size as usize - buf.len()); - - // copy these bytes into our buffer - buf.extend_from_slice(&int_buf[..len_to_copy]); - // and consume them in the buffered reader. - blob_reader.consume(len_to_copy); - } + // copy things from the internal buffer into buf to fill it till up until size + tokio::io::copy(&mut blob_reader.as_mut().take(size as u64), &mut buf).await?; Ok(buf) }); |