jmcnamara / rust_xlsxwriter

A Rust library for creating Excel XLSX files.
https://crates.io/crates/rust_xlsxwriter
Apache License 2.0
316 stars 25 forks source link

Don't depend on tempfile #12

Closed jacobsvante closed 1 year ago

jacobsvante commented 1 year ago

Feature Request

As can be seen here, rust_xlsxwriter currently depends on the tempfile crate, which in turn means that a /tmp directory (or equivalent) needs to be available. This isn't the case in Kubernetes environments by default, which is how I noticed this. I guess wasm environments would also have trouble with this.

Wouldn't it make more sense to default to in-memory storage, and make tempfile an optional feature to the crate? Then with that feature enabled, one could opt in to the file-creating behavior using an associated function, e.g. Workbook::new_tempfile_backed().

jacobsvante commented 1 year ago

Another API suggestion:

let mut wb = Workbook::new();
wb.use_tempfile_when_larger_than(5_000_000);

In this case temp file would never be created unless data grows to a size of 5 MBytes or more.

jmcnamara commented 1 year ago

Thanks for the feedback.

rust_xlsxwriter currently depends on the tempfile crate, which in turn means that a /tmp directory (or equivalent) needs to be available.

There are two items on the roadmap to deal with that:

The Python version supports both of those: https://xlsxwriter.readthedocs.io/workbook.html#constructor

However, I will need to balance this with a 'low/constant memory mode' feature (also supported in the Python version) where tempfile will be required as a backend for worksheets.

However, in the short term I may just remove the tempfile requirement (if there is no performance difference) and re-introduce it later as an optional feature for constant memory mode.

jmcnamara commented 1 year ago

I've pushed a version to main that removes the dependency on the tempfile crate. You can test it if you get a chance.

jmcnamara commented 1 year ago

Thanks for the suggestion.

Fixed in version 0.12.1. Closing.

jacobsvante commented 1 year ago

Great job! Thank you!!

jacobsvante commented 1 year ago

However, I will need to balance this with a 'low/constant memory mode' feature (also supported in the Python version) where tempfile will be required as a backend for worksheets.

Agreed. Having this option will most likely be important for many scenarios, no matter how memory efficient Rust is.