zino_storage

Struct NamedFile

Source
pub struct NamedFile { /* private fields */ }
Expand description

A file with an associated name.

Implementations§

Source§

impl NamedFile

Source

pub fn new(file_name: impl Into<String>) -> Self

Creates a new instance with the specific file name.

Source

pub fn set_field_name(&mut self, field_name: impl Into<String>)

Sets the field name.

Source

pub fn set_file_name(&mut self, file_name: impl Into<String>)

Sets the file name.

Source

pub fn set_content_type(&mut self, content_type: Mime)

Sets the content type.

Source

pub fn set_bytes(&mut self, bytes: impl Into<Bytes>)

Sets the bytes.

Source

pub fn set_extra_attribute(&mut self, key: &str, value: impl Into<JsonValue>)

Sets the extra attribute.

§Note

Currently, we support the following built-in attributes: checksum | chunk_number | chunk_size | total_chunks.

Source

pub fn append_extra_attributes(&mut self, attrs: &mut Map)

Appends the extra attributes.

Source

pub fn field_name(&self) -> Option<&str>

Returns the field name corresponding to the file.

Source

pub fn file_name(&self) -> Option<&str>

Returns the file name.

Source

pub fn content_type(&self) -> Option<&Mime>

Returns the content type.

Source

pub fn file_size(&self) -> u64

Returns the file size.

Source

pub fn bytes(&self) -> Bytes

Returns the bytes.

Source

pub fn extra(&self) -> &Map

Returns a reference to the extra attributes.

Source

pub fn chunk_number(&self) -> Option<usize>

Returns the chunk number for the file.

Source

pub fn chunk_size(&self) -> Option<usize>

Returns the chunk size for the file.

Source

pub fn total_chunks(&self) -> Option<usize>

Returns the total number of file chunks.

Source

pub fn checksum(&self) -> Bytes

Returns the checksum for the file.

§Note

If you would like to obtain a hex-formated string, you can use the LowerHex or UpperHex implementations for Bytes.

Source

pub fn etag(&self) -> EntityTag

Returns the ETag for the file.

Source

pub fn content_md5(&self) -> String

Returns the content MD5.

Source

pub fn to_hex_string(&self) -> String

Returns the hex representation of the file bytes.

Source

pub fn to_base64_string(&self) -> String

Returns the base64 representation of the file bytes.

Source

pub fn read_string(&mut self, data: String) -> Result<(), Error>

Reads the string and sets the bytes.

Source

pub fn read_hex_string(&mut self, data: &str) -> Result<(), Error>

Reads the hex string and sets the bytes.

Source

pub fn read_base64_string(&mut self, data: &str) -> Result<(), Error>

Reads the base64 string and sets the bytes.

Source

pub fn read_from_local(&mut self, path: impl AsRef<Path>) -> Result<(), Error>

Reads the entire contents of a local file and sets the bytes.

Source

pub fn write(&self, path: impl AsRef<Path>) -> Result<(), Error>

Writes the bytes into a file at the path. If the extra attributes contain a chunk_number value, a .{chunk_number}.part suffix will be adjoined to the path.

Source

pub fn append(&self, path: impl AsRef<Path>) -> Result<(), Error>

Appends the bytes into a file at the path.

Source

pub fn encrypt_with(&mut self, key: impl AsRef<[u8]>) -> Result<(), Error>

Encrypts the file with a key.

Source

pub fn decrypt_with(&mut self, key: impl AsRef<[u8]>) -> Result<(), Error>

Decrypts the file with a key.

Source

pub fn rename_file_stem(&mut self, file_stem: &str) -> Result<(), Error>

Renames the stem portion of the file name.

Source

pub fn split_chunks(&self, chunk_size: usize) -> Vec<Self>

Splits the file into chunks with the chunk_size. The file name of chunks will end with .{chunk_number}.part and the extra attributes will contain the chunk_number and total_chunks.

Source

pub fn try_concat_chunks( path: impl AsRef<Path>, total_chunks: usize, ) -> Result<Self, Error>

Attempts to concat the file chunks into a whole. The path should not contain the .{chunk_number}.part suffix.

Source

pub fn try_from_local(path: impl AsRef<Path>) -> Result<Self, Error>

Attempts to create an instance from reading a local file.

Source

pub async fn try_from_multipart_field(field: Field<'_>) -> Result<Self, Error>

Attempts to create an instance from a field in a multipart stream.

Source

pub async fn try_from_multipart(multipart: Multipart<'_>) -> Result<Self, Error>

Attempts to create a file in a multipart stream. If the extra attributes contain a chunk_size or checksum value, the file integrity will be checked.

Source

pub async fn try_collect_from_multipart( multipart: Multipart<'_>, ) -> Result<Vec<Self>, Error>

Attempts to create a list of files in a multipart stream.

Source

pub async fn download_from( url: &str, options: Option<&Map>, ) -> Result<Self, Error>

Available on crate feature http-client only.

Downloads a file from the URL.

Source

pub async fn upload_to( &self, url: &str, options: Option<&Map>, ) -> Result<Response, Error>

Available on crate feature http-client only.

Uploads the file to the URL.

Trait Implementations§

Source§

impl AsRef<[u8]> for NamedFile

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for NamedFile

Source§

fn clone(&self) -> NamedFile

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NamedFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NamedFile

Source§

fn default() -> NamedFile

Returns the “default value” for a type. Read more
Source§

impl<'a> From<&'a NamedFile> for Buffer

Available on crate feature accessor only.
Source§

fn from(file: &'a NamedFile) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a NamedFile> for Bytes

Source§

fn from(file: &'a NamedFile) -> Self

Converts to this type from the input type.
Source§

impl From<NamedFile> for Buffer

Available on crate feature accessor only.
Source§

fn from(file: NamedFile) -> Self

Converts to this type from the input type.
Source§

impl From<NamedFile> for Bytes

Source§

fn from(file: NamedFile) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToHex for T
where T: AsRef<[u8]>,

Source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
Source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSendSync for T