Crate remi_fs

Crate remi_fs 

Source
Expand description

§🐻‍❄️🧶 remi_fs

This crate is an official implementation of remi::StorageService that uses the local filesystem for operations.

§Example

// Cargo.toml:
//
// [dependencies]
// remi = "^0"
// remi-fs = "^0"
// tokio = { version = "^1", features = ["full"] }

use remi_fs::{StorageService, StorageConfig};
use remi::{StorageService as _, UploadRequest};

#[tokio::main]
async fn main() {
    // Initialize a `StorageService` that uses your local filesystem for storing files.
    let storage = StorageService::new("./data");

    // Next, we will run the `init` function which will create
    // the ./data directory if it doesn't exist already.
    storage.init().await.unwrap();

    // We define a `UploadRequest`, which will set the content type to `text/plain` and set the
    // contents of `weow.txt` to `weow fluff`.
    let upload = UploadRequest::default()
        .with_content_type(Some("text/plain"))
        .with_data("weow fluff");

    // Let's upload it!
    storage.upload("./weow.txt", upload).await.unwrap();

    // Let's check if it exists! This `assert!` will panic if it failed
    // to upload.
    assert!(storage.exists("./weow.txt").await.unwrap());
}

§Crate Features

Crate FeaturesDescriptionEnabled by default?
unstableTap into unstable features from remi_fs and the remi crate.No.
serde_yaml_ngAllows to detect YAML documents with the serde_yaml_ng crate.No.
serde_jsonUses the serde_json crate to detect JSON documents and return application/jsonNo.
file-formatUses the file-format crate to find media types on any external datatype.Yes.
tracingEnables the use of tracing::instrument and emit events for actions by the crate.No.
inferUses the infer crate to infer external datatypes and map them to their media type.Yes.
serdeEnables the use of serde in StorageConfigNo.
logEmits log records for actions by the crateNo.

Structs§

StorageConfig
Represents the main configuration of using the StorageService implementation of remi-fs.
StorageService
Represents an implementation of a StorageService for the local filesystem.

Constants§

DEFAULT_CONTENT_TYPE
Default content type given from a ContentTypeResolver

Traits§

ContentTypeResolver
Represents a resolver to resolve content types from a byte slice.

Functions§

default_resolverfile-format
Default implementation of a ContentTypeResolver. It can detect any format that the [file-format] and infer crates can plus: