Rust

local

Module

[Local]: files on the local disk.

Contents

use utopia_storage::Local;
Rust
pub struct Local

Files on the local disk, under a root directory.

Writes are atomic: the body goes to a temporary file next to the target, which is renamed over it, so a reader sees the whole old file or the whole new one. The ETag of a local file is its MD5 hash. A chunked upload keeps its chunks in a tmp_<name> directory next to the target until they are joined.

Reads and writes do their file I/O in one blocking call each (a whole small file at once), on the worker itself rather than through tokio's blocking pool: block_in_place on a multi-threaded runtime, in place on a current-thread one. Larger bodies stream from the blocking pool.

Rust
use utopia_storage::{Body, Device, Local};

let dir = std::env::temp_dir().join("utopia-storage-doc-local");
let device = Local::new(dir.to_str().unwrap());
let path = device.path("hello.txt");

let etag = device.write(&path, Body::from("Hello World"), "text/plain").await?;
assert_eq!(etag, "b10a8db164e0754105b7a99be72e3fe5");
assert_eq!(&device.read(&path, 0, None, None).await?.bytes().await.unwrap()[..], b"Hello World");
assert!(device.delete(&path, false).await?);