Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/reader_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,24 @@ impl WrappedFile {
let (sender, receiver) = oneshot::channel();
let file = self.inner.clone();
spawn_local(async move {
let subset_blob = file
.slice_with_i32_and_i32(
let subset_blob = if (range.start <= i32::MAX as u64) && (range.end <= i32::MAX as u64)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having two branches for i32 and f64, we can probably first check that the range start and end is representable as an integer in f64, and then only use the f64 slice api

{
file.slice_with_i32_and_i32(
range.start.try_into().unwrap(),
range.end.try_into().unwrap(),
)
.unwrap();
.unwrap()
} else {
let start = range.start as f64;
if start as u64 != range.start {
panic!("Cannot safely convert start index of {range:?}");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of panicking, we should change this method to be fallible and return an Err

}
let end = range.end as f64;
if end as u64 != range.end {
panic!("Cannot safely convert start index of {range:?}");
}
file.slice_with_f64_and_f64(start, end).unwrap()
};
let buf = JsFuture::from(subset_blob.array_buffer()).await.unwrap();
let out_vec = Uint8Array::new_with_byte_offset(&buf, 0).to_vec();
sender.send(out_vec).unwrap();
Expand Down
Loading