Skip to content

Commit

Permalink
adjust comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Mar 4, 2023
1 parent 7ff65c1 commit d325810
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/tauri/src/asset_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn asset_protocol_handler(

let mut buf = Vec::with_capacity(bytes_to_read as usize);
file.seek(SeekFrom::Start(start)).await?;
file.read_buf(&mut buf).await?;
file.take(bytes_to_read).read_to_end(&mut buf).await?;

resp = resp.header(CONTENT_RANGE, format!("bytes {start}-{end}/{len}"));
resp = resp.header(CONTENT_LENGTH, end + 1 - start);
Expand Down Expand Up @@ -162,7 +162,7 @@ pub fn asset_protocol_handler(
.write_all(format!("{CONTENT_RANGE}: bytes {start}-{end}/{len}\r\n").as_bytes())
.await?;

// separator to indicate start of the range body
// write the separator to indicate the start of the range body
buf.write_all("\r\n".as_bytes()).await?;

// calculate number of bytes needed to be read
Expand Down
5 changes: 3 additions & 2 deletions examples/streaming/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,18 @@ fn main() {
buf.write_all(format!("{CONTENT_TYPE}: video/mp4\r\n").as_bytes())?;
buf.write_all(format!("{CONTENT_RANGE}: bytes {start}-{end}/{len}\r\n").as_bytes())?;

// separator to indicate start of the range body
// write the separator to indicate the start of the range body
buf.write_all("\r\n".as_bytes())?;

// calculate number of bytes needed to be read
let bytes_to_read = end + 1 - start;

let mut local_buf = vec![0_u8, bytes_to_read as usize];
let mut local_buf = vec![0_u8; bytes_to_read as usize];
file.seek(SeekFrom::Start(start));
file.read_exact(&mut local_buf);
buf.extend_from_slice(&local_buf);
}
// all ranges have been written, write the closing boundary
buf.write_all(boundary_closer.as_bytes())?;

resp.body(buf)
Expand Down

0 comments on commit d325810

Please sign in to comment.