Skip to content

Commit

Permalink
fix: Handle greater than file size read limits
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Jan 4, 2024
1 parent 2172dbd commit c52a5d0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions wnfs/src/public/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ impl PublicFile {
len_limit: Option<usize>,
store: &'a impl BlockStore,
) -> Result<Vec<u8>> {
let size = self.size(store).await?;
let mut reader = self.stream_content(byte_offset, store).await?;
if let Some(len) = len_limit {
let len = std::cmp::min(len as u64, size as u64 - byte_offset) as usize;
let mut buffer = vec![0; len];
reader.read_exact(&mut buffer).await?;
Ok(buffer)
Expand Down

0 comments on commit c52a5d0

Please sign in to comment.