diff --git a/crates/polars-io/src/utils/other.rs b/crates/polars-io/src/utils/other.rs index f4ef629821a9..e6f51b5f3b6d 100644 --- a/crates/polars-io/src/utils/other.rs +++ b/crates/polars-io/src/utils/other.rs @@ -1,6 +1,8 @@ #[cfg(any(feature = "ipc_streaming", feature = "parquet"))] use std::borrow::Cow; use std::io::Read; +#[cfg(target_os = "emscripten")] +use std::io::{Seek, SeekFrom}; use once_cell::sync::Lazy; use polars_core::prelude::*; @@ -23,6 +25,15 @@ pub fn get_reader_bytes( { let mut options = memmap::MmapOptions::new(); options.offset(offset); + + // Set mmap size based on seek to end when running under Emscripten + #[cfg(target_os = "emscripten")] + { + let mut file = file; + let size = file.seek(SeekFrom::End(0)).unwrap(); + options.len((size - offset) as usize); + } + let mmap = MMapSemaphore::new_from_file_with_options(file, options)?; Ok(ReaderBytes::Owned(MemSlice::from_mmap(Arc::new(mmap)))) } else {