Skip to content

To support AsyncRead-only requests, we need to return Option<u64> from SeekableStream::len() #4081

@heaths

Description

@heaths

If Storage wants to make it possible for customers to only upload a "stream" supporting futures::io::AsyncRead, we need to redesign SeekableStream::len() and is_empty() to return an Option<T>. This is because we cannot get the size using AsyncRead alone. We need AsyncSeek support and it has to be rewindable (which could fail).

One idea is to make the ReadStream in #4067 a builder like the FileStream I added in #4057 where with_buffer_size() can be called to specify a size, or - with an implementation specific to AsyncSeek being implemented.

One idea is something like,

pub struct ReadStream<R> {
    reader: R,
    len: Option<u64>,
    buffer_size: usize,
}

// We'd probably want an actual builder here so it's final, but just as an example...
impl<R: AsyncRead + Unpin + Send + Sync> ReadStream<R> {
    pub fn new(reader: R) -> Self {
        todo!()
    }
    pub fn with_buffer_size(self, buffer_size: usize) -> Self {
        todo!()
    }
    pub fn with_len(self, len: u64) -> Self {
        todo!()
    }
}

impl<R: AsyncRead + AsyncSeek + Unpin + Send + Sync> ReadStream<R> {
    pub async fn determine_size(self) -> Result<Self> {
        todo!()
    }
}

Metadata

Metadata

Assignees

Labels

Azure.CoreThe azure_core crateClientThis issue points to a problem in the data-plane of the library.blocking-releaseBlocks releasedesign-discussionAn area of design currently under discussion and open to team and community feedback.

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions