Function spooled_tempfile

Source
pub fn spooled_tempfile(max_size: usize) -> SpooledTempFile 
Expand description

Create a new SpooledTempFile. Also see spooled_tempfile_in.

§Security

This variant is secure/reliable in the presence of a pathological temporary file cleaner.

§Backing Storage

By default, the underlying temporary file will be created in your operating system’s temporary file directory which is often an in-memory filesystem. You may want to consider using spooled_tempfile_in instead, passing a storage-backed filesystem (e.g., /var/tmp on Linux).

§Resource Leaking

The temporary file will be automatically removed by the OS when the last handle to it is closed. This doesn’t rely on Rust destructors being run, so will (almost) never fail to clean up the temporary file.

§Examples

use tempfile::spooled_tempfile;
use std::io::Write;

let mut file = spooled_tempfile(15);

writeln!(file, "short line")?;
assert!(!file.is_rolled());

// as a result of this write call, the size of the data will exceed
// `max_size` (15), so it will be written to a temporary file on disk,
// and the in-memory buffer will be dropped
writeln!(file, "marvin gardens")?;
assert!(file.is_rolled());