Skip to content

Commit

Permalink
content range
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine committed Jan 22, 2024
1 parent fde7f6d commit e988e62
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions crates/s3s-fs/src/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ fn normalize_path(path: &Path, delimiter: &str) -> Option<String> {
Some(normalized)
}

/// <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range>
fn fmt_content_range(start: u64, end_inclusive: u64, size: u64) -> String {
format!("bytes {start}-{end_inclusive}/{size}")
}

#[async_trait::async_trait]
impl S3 for FileSystem {
#[tracing::instrument]
Expand Down Expand Up @@ -199,10 +204,9 @@ impl S3 for FileSystem {
None => (file_len, None),
Some(range) => {
let file_range = range.check(file_len)?;
(
file_range.end - file_range.start,
Some(format!("bytes {}-{}/{file_len}", file_range.start, file_range.end - 1)),
)
let content_length = file_range.end - file_range.start;
let content_range = fmt_content_range(file_range.start, file_range.end - 1, file_len);
(content_length, Some(content_range))
}
};
let content_length_usize = try_!(usize::try_from(content_length));
Expand Down

0 comments on commit e988e62

Please sign in to comment.