Rust

device

Module

The Device trait every storage backend implements, and the values its operations take and return.

Contents

use utopia_storage::FileInfo;
Rust
pub struct FileInfo

Size, last modification and ETag of a file.

use utopia_storage::FileList;
Rust
pub struct FileList

One page of a file listing.

use utopia_storage::Metadata;
Rust
pub struct Metadata

The state of a chunked upload, carried by the caller from one chunk to the next (Appwrite stores it with the upload).

use utopia_storage::UploadInfo;
Rust
pub struct UploadInfo

A multipart upload that was prepared but neither finalized nor aborted.

use utopia_storage::UploadList;
Rust
pub struct UploadList

One page of multipart uploads in progress.

use utopia_storage::Acl;
Rust
pub enum Acl

An Amazon S3 canned ACL applied to written objects.

use utopia_storage::DeviceType;
Rust
pub enum DeviceType

The kind of a device.

use utopia_storage::Part;
Rust
pub enum Part

What a device knows about a chunk it received.

use utopia_storage::Device;
Rust
pub trait Device: Send + Sync + Any

A storage backend: where files are written, read, listed and deleted.

Paths are absolute device paths, such as Device::path builds from a file name. Uploads come in chunks: Device::upload each one with the same Metadata, and the device joins them once all have arrived. Writes return the ETag of what they wrote; Device::create and Device::replace are conditional, so of several writers racing for the same file exactly one wins.

Implement it to add a device: copy is the streamed copy every device can fall back to.

Implemented byLocalS3Telemetry
use utopia_storage::absolute_path;
Rust
pub fn absolute_path(path: &str) -> String

Resolves ., .. and repeated separators in a path, without touching the disk, into an absolute path.

Rust
assert_eq!(utopia_storage::absolute_path("a/./b/../c//d"), "/a/c/d");
assert_eq!(utopia_storage::absolute_path("../.."), "/");
use utopia_storage::copy;
Rust
pub async fn copy(from: &dyn Device, source: &str, target: &str, to: Option<&dyn Device>, chunk_size: i64) -> Result<bool>

The streamed copy every device can fall back to: a file up to chunk_size is read and written whole, a larger one goes up as a chunked upload, which is aborted if a chunk fails once a multipart upload was started.

use utopia_storage::move_file;
Rust
pub async fn move_file(device: &dyn Device, source: &str, target: &str) -> Result<bool>

The move every device can fall back to: a copy, then a delete of the source. false when source and target are the same.

Rust
pub const COPY_CHUNK_SIZE: i64 = 20_000_000

The largest piece copy moves at once between devices: 20 MB.