device
ModuleThe Device trait every storage backend implements, and the values its
operations take and return.
Contents
use utopia_storage::FileInfo;pub struct FileInfoSize, last modification and ETag of a file.
use utopia_storage::FileList;pub struct FileListOne page of a file listing.
use utopia_storage::Metadata;pub struct MetadataThe 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;pub struct UploadInfoA multipart upload that was prepared but neither finalized nor aborted.
use utopia_storage::UploadList;pub struct UploadListOne page of multipart uploads in progress.
use utopia_storage::Acl;pub enum AclAn Amazon S3 canned ACL applied to written objects.
use utopia_storage::DeviceType;pub enum DeviceTypeThe kind of a device.
use utopia_storage::Part;pub enum PartWhat a device knows about a chunk it received.
use utopia_storage::Device;pub trait Device: Send + Sync + AnyA 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.
use utopia_storage::absolute_path;pub fn absolute_path(path: &str) -> StringResolves ., .. and repeated separators in a path, without touching
the disk, into an absolute path.
assert_eq!(utopia_storage::absolute_path("a/./b/../c//d"), "/a/c/d");
assert_eq!(utopia_storage::absolute_path("../.."), "/");use utopia_storage::copy;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;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.
pub const COPY_CHUNK_SIZE: i64 = 20_000_000The largest piece copy moves at once between devices: 20 MB.