pub struct PayloadSource { /* private fields */ }Expand description
Where one put reads its payload, and what it knows about it up front.
The length is a hint and never a promise: a source that knows it lets the
put pick the cheaper transport and declare a Content-Length, and a
source that does not know it — a pipe, a socket, standard input — takes
exactly the same path and discovers the length as it goes.
Implementations§
Source§impl PayloadSource
impl PayloadSource
Sourcepub fn stream(stream: PayloadStream) -> Self
pub fn stream(stream: PayloadStream) -> Self
A source of unknown length.
Sourcepub fn sized_stream(stream: PayloadStream, size_bytes: u64) -> Self
pub fn sized_stream(stream: PayloadStream, size_bytes: u64) -> Self
A source whose complete length the caller already knows.
The length is used to choose a transport and to frame the request; a source that delivers a different number of bytes is still uploaded faithfully, and it is the bytes that decide what is stored.
Sourcepub fn reader<R>(reader: R) -> Self
pub fn reader<R>(reader: R) -> Self
A source of unknown length reading from anything asynchronous — standard input, a socket, a decompressor.
Sourcepub async fn open_file(path: impl AsRef<Path>) -> Result<Self>
pub async fn open_file(path: impl AsRef<Path>) -> Result<Self>
A source reading one local file, whose length is known before the first byte moves.
Sourcepub fn size_bytes(&self) -> Option<u64>
pub fn size_bytes(&self) -> Option<u64>
Complete length when the source knows it.
Sourcepub fn into_stream(self) -> (PayloadStream, Option<u64>)
pub fn into_stream(self) -> (PayloadStream, Option<u64>)
Splits the source into the stream to read and the length it declared, for a caller that has to restate it in another crate’s terms.