async fn put<S>(&self, location: &str, bytes: S, length: usize) -> InternalResult<()>
    where
        S: Stream<Item = io::Result<Bytes>> + Send + Sync + 'static,
    {
        let content = bytes
            .map_ok(|b| bytes::BytesMut::from(&b[..]))
            .try_concat()
            .await
            .context(UnableToPutDataInMemory)?;

        ensure!(
            content.len() == length,
            DataDoesNotMatchLength {
                actual: content.len(),
                expected: length,
            }
        );

        let path = self.path(location);

        let mut file = match fs::File::create(&path).await {
            Ok(f) => f,
            Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
                let parent = path
                    .parent()
                    .context(UnableToCreateFile { path: &path, err })?;
                fs::create_dir_all(&parent)
                    .await
                    .context(UnableToCreateDir { path: parent })?;

                match fs::File::create(&path).await {
                    Ok(f) => f,
                    Err(err) => return UnableToCreateFile { path, err }.fail(),
                }
            }
            Err(err) => return UnableToCreateFile { path, err }.fail(),
        };

        tokio::io::copy(&mut &content[..], &mut file)
            .await
            .context(UnableToCopyDataToFile)?;

        Ok(())
    }
/// Save the provided bytes to the specified location.
Save the provided bytes to the specified location.
Save the provided bytes to the specified location .
async fn put<S>(&self, location: &str, bytes: S, length: usize) -> InternalResult<()>
    where
        S: Stream<Item = io::Result<Bytes>> + Send + Sync + 'static,
    {
        let content = bytes
            .map_ok(|b| bytes::BytesMut::from(&b[..]))
            .try_concat()
            .await
            .context(UnableToPutDataInMemory)?;
        ensure!(
            content.len() == length,
            DataDoesNotMatchLength {
                actual: content.len(),
                expected: length,
            }
        );
        let path = self.path(location);
        let mut file = match fs::File::create(&path).await {
            Ok(f) => f,
            Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
                let parent = path
                    .parent()
                    .context(UnableToCreateFile { path: &path, err })?;
                fs::create_dir_all(&parent)
                    .await
                    .context(UnableToCreateDir { path: parent })?;
                match fs::File::create(&path).await {
                    Ok(f) => f,
                    Err(err) => return UnableToCreateFile { path, err }.fail(),
                }
            }
            Err(err) => return UnableToCreateFile { path, err }.fail(),
        };
        tokio::io::copy(&mut &content[..], &mut file)
            .await
            .context(UnableToCopyDataToFile)?;
        Ok(())
    }
async fn put < S > ( & self , location : & str , bytes : S , length : usize ) -> InternalResult < ( ) > where S : Stream < Item = io :: Result < Bytes > > + Send + Sync + ' static , { let content = bytes . map_ok ( | b | bytes :: BytesMut :: from ( & b [ .. ] ) ) . try_concat ( ) . await . context ( UnableToPutDataInMemory ) ? ; ensure ! ( content len ( ) length DataDoesNotMatchLength { actual content len ( ) expected length } ) ; let path = self . path ( location ) ; let mut file = match fs :: File :: create ( & path ) . await { Ok ( f ) => f , Err ( err ) if err . kind ( ) == std :: io :: ErrorKind :: NotFound => { let parent = path . parent ( ) . context ( UnableToCreateFile { path : & path , err } ) ? ; fs :: create_dir_all ( & parent ) . await . context ( UnableToCreateDir { path : parent } ) ? ; match fs :: File :: create ( & path ) . await { Ok ( f ) => f , Err ( err ) => return UnableToCreateFile { path , err } . fail ( ) , } } Err ( err ) => return UnableToCreateFile { path , err } . fail ( ) , } ; tokio :: io :: copy ( & mut & content [ .. ] , & mut file ) . await . context ( UnableToCopyDataToFile ) ? ; Ok ( ( ) ) }
Save the provided bytes to the specified location.
Save the provided bytes to the specified location .
&self
location
&str
bytes
S
length
usize