pub async fn download<W: io::Write>(
        &self,
        file_name: String,
        output: &mut W,
    ) -> Result<(), Error> {
        let mut get_object_request = GetObjectRequest::default();
        get_object_request.bucket = self.bucket.to_string().to_owned();
        get_object_request.key = file_name.to_owned();

        let result = self.s3_client.get_object(get_object_request).await;

        let object = match result {
            Ok(obj) => obj,
            Err(e) => {
                info!("Error downloading object for: {} {:?}", file_name, e);
                return Err(Error::new(ErrorKind::Other, "Error downloading object"));
            }
        };

        let len = object.content_length.unwrap();
        let now = SystemTime::now();
        info!(
            "Downloading Object: {:?} and length: {}",
            object.metadata, len
        );
        let mut stream = object.body.unwrap().into_async_read();

        let mut buf = vec![0u8; 1024];
        //Naive Stream read + write
        loop {
            let number = stream.read(&mut buf).await?;
            if number == 0 {
                output.flush()?;
                info!(
                    "Finished Object download: {:?} in: {:?} seconds",
                    object.metadata,
                    now.elapsed().unwrap().as_secs()
                );
                break;
            }
            output.write(&buf[0..number]);
        }
        return Ok(());
    }
//Downloads to a file and returns the buffer.
//Consider making this a BufReader
Downloads to a file and returns the buffer.
Consider making this a BufReader
Downloads to a file and returns the buffer . Consider making this a BufReader
pub async fn download<W: io::Write>(
        &self,
        file_name: String,
        output: &mut W,
    ) -> Result<(), Error> {
        let mut get_object_request = GetObjectRequest::default();
        get_object_request.bucket = self.bucket.to_string().to_owned();
        get_object_request.key = file_name.to_owned();
        let result = self.s3_client.get_object(get_object_request).await;
        let object = match result {
            Ok(obj) => obj,
            Err(e) => {
                info!("Error downloading object for: {} {:?}", file_name, e);
                return Err(Error::new(ErrorKind::Other, "Error downloading object"));
            }
        };
        let len = object.content_length.unwrap();
        let now = SystemTime::now();
        info!(
            "Downloading Object: {:?} and length: {}",
            object.metadata, len
        );
        let mut stream = object.body.unwrap().into_async_read();
        let mut buf = vec![0u8; 1024];
        //Naive Stream read + write
        loop {
            let number = stream.read(&mut buf).await?;
            if number == 0 {
                output.flush()?;
                info!(
                    "Finished Object download: {:?} in: {:?} seconds",
                    object.metadata,
                    now.elapsed().unwrap().as_secs()
                );
                break;
            }
            output.write(&buf[0..number]);
        }
        return Ok(());
    }
pub async fn download < W : io :: Write > ( & self , file_name : String , output : & mut W , ) -> Result < ( ) , Error > { let mut get_object_request = GetObjectRequest :: default ( ) ; get_object_request . bucket = self . bucket . to_string ( ) . to_owned ( ) ; get_object_request . key = file_name . to_owned ( ) ; let result = self . s3_client . get_object ( get_object_request ) . await ; let object = match result { Ok ( obj ) => obj , Err ( e ) => { info ! ( " " file_name e ) ; return Err ( Error :: new ( ErrorKind :: Other , " " ) ) ; } } ; let len = object . content_length . unwrap ( ) ; let now = SystemTime :: now ( ) ; info ! ( " " object metadata len ) ; let mut stream = object . body . unwrap ( ) . into_async_read ( ) ; let mut buf = vec ! [ 0u8 1024 ] ; //Naive Stream read + write loop { let number = stream . read ( & mut buf ) . await ? ; if number == 0 { output . flush ( ) ? ; info ! ( " " object metadata now elapsed ( ) unwrap ( ) as_secs ( ) ) ; break ; } output . write ( & buf [ 0 .. number ] ) ; } return Ok ( ( ) ) ; }
Downloads to a file and returns the buffer.
Downloads to a file and returns the buffer .
&self
file_name
String
output
&mut W
&self
file_name
String
output
&mut W