Skip to main content

FileInput

Struct FileInput 

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

A file to process: a local path, bytes in memory, an async reader, or a document that is already stored.

Anything path-like converts into a FileInput, so most calls take a plain string:

use wellfriend::FileInput;

wf.tools().compress_pdf("scan.pdf", None).await?;                            // a path
wf.tools().compress_pdf(FileInput::bytes(data, "scan.pdf"), None).await?;      // bytes
wf.tools().compress_pdf(FileInput::document("doc_8kq2W1"), None).await?;       // stored

The content type is taken from the file name’s extension.

Implementations§

Source§

impl FileInput

Source

pub fn path(path: impl AsRef<Path>) -> Self

A local file, streamed from disk.

Source

pub fn bytes(data: impl Into<Bytes>, filename: impl Into<String>) -> Self

Bytes in memory, with the file name to store them under.

Source

pub fn file(file: File, filename: impl Into<String>) -> Self

An open file, streamed from its current position to the end.

Source

pub fn reader( reader: impl AsyncRead + Send + Unpin + 'static, size: u64, filename: impl Into<String>, ) -> Self

Any async reader with its exact size in bytes. Files above the resumable-upload threshold are sent in parts, holding one part (8 MiB) in memory at a time; above 50 MiB the API needs the file’s SHA-256, so give it with FileInput::with_sha256 or pass a path.

Source

pub fn document(document_id: impl Into<String>) -> Self

A document already stored in the workspace (its current version). Nothing is uploaded.

Source

pub fn version( document_id: impl Into<String>, version_id: impl Into<String>, ) -> Self

One immutable version of a stored document. Nothing is uploaded.

Source

pub fn with_filename(self, filename: impl Into<String>) -> Self

Stores the upload under this file name instead of the path’s own name.

Source

pub fn with_content_type(self, content_type: impl Into<String>) -> Self

Sends this content type instead of the one detected from the file name.

Source

pub fn with_sha256(self, sha256: impl Into<String>) -> Self

The file’s SHA-256 in hex, when you already know it. Lets the API skip storing bytes it already has, and is required for reader inputs above 50 MiB.

Source

pub fn is_document(&self) -> bool

True for an input that refers to a stored document.

Trait Implementations§

Source§

impl Debug for FileInput

Source§

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

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

impl From<&Document> for FileInput

Source§

fn from(document: &Document) -> Self

Converts to this type from the input type.
Source§

impl From<&Path> for FileInput

Source§

fn from(path: &Path) -> Self

Converts to this type from the input type.
Source§

impl From<&PathBuf> for FileInput

Source§

fn from(path: &PathBuf) -> Self

Converts to this type from the input type.
Source§

impl From<&String> for FileInput

Source§

fn from(path: &String) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for FileInput

Source§

fn from(path: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Document> for FileInput

Source§

fn from(document: Document) -> Self

Converts to this type from the input type.
Source§

impl From<FileInput> for ToolInput

Source§

fn from(file: FileInput) -> Self

Converts to this type from the input type.
Source§

impl From<PathBuf> for FileInput

Source§

fn from(path: PathBuf) -> Self

Converts to this type from the input type.
Source§

impl From<String> for FileInput

Source§

fn from(path: String) -> Self

Converts to this type from the input type.
Source§

impl From<VersionRef> for FileInput

Source§

fn from(reference: VersionRef) -> 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> ErasedDestructor for T
where T: 'static,

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> MaybeSendSync for T

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<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