ext/polars/src/file.rs in polars-df-0.1.1 vs ext/polars/src/file.rs in polars-df-0.1.2

- old
+ new

@@ -1,19 +1,20 @@ use magnus::{Error, RString, Value}; use polars::io::mmap::MmapBytesReader; -use std::fs::{File, OpenOptions}; +use std::fs::File; use std::io::Cursor; use std::path::PathBuf; use crate::RbResult; pub fn get_file_like(f: Value, truncate: bool) -> RbResult<File> { - OpenOptions::new() - .write(true) - .create(true) - .truncate(truncate) - .open(f.try_convert::<PathBuf>()?) - .map_err(|e| Error::runtime_error(e.to_string())) + let str_slice = f.try_convert::<PathBuf>()?; + let f = if truncate { + File::create(str_slice).map_err(|e| Error::runtime_error(e.to_string()))? + } else { + File::open(str_slice).map_err(|e| Error::runtime_error(e.to_string()))? + }; + Ok(f) } pub fn get_mmap_bytes_reader(rb_f: Value) -> RbResult<Box<dyn MmapBytesReader>> { if let Ok(bytes) = rb_f.funcall::<_, _, RString>("read", ()) { let bytes = unsafe { bytes.as_slice() };