/// Stream the bytes of a given HTTP response body into the given file
Stream the bytes of a given HTTP response body into the given file
Stream the bytes of a given HTTP response body into the given file
async fn stream_response_body_to_file(
        &self,
        mut response: Response<Body>,
        file_path: &Path,
    ) -> FileDownloadResult<()> {
        let mut output_file = File::create(file_path)
            .map_err(|e| FileDownloadError::file_create_error(file_path, e))?;
        while let Some(next) = tokio::time::timeout(self.timeout, response.data())
            .await
            .map_err(|_| FileDownloadError::TimeoutError)?
        {
            let chunk = next.map_err(FileDownloadError::from)?;
            output_file
                .write_all(&chunk)
                .map_err(|e| FileDownloadError::file_write_error(file_path, e))?;
        }
        Ok(())
    }
async fn stream_response_body_to_file ( & self , mut response : Response < Body > , file_path : & Path , ) -> FileDownloadResult < ( ) > { let mut output_file = File :: create ( file_path ) . map_err ( | e | FileDownloadError :: file_create_error ( file_path , e ) ) ? ; while let Some ( next ) = tokio :: time :: timeout ( self . timeout , response . data ( ) ) . await . map_err ( | _ | FileDownloadError :: TimeoutError ) ? { let chunk = next . map_err ( FileDownloadError :: from ) ? ; output_file . write_all ( & chunk ) . map_err ( | e | FileDownloadError :: file_write_error ( file_path , e ) ) ? ; } Ok ( ( ) ) }
Stream the bytes of a given HTTP response body into the given file
Stream the bytes of a given HTTP response body into the given file
&self
response
Response<Body>
file_path
&Path