async fn download_file_from_net(
    safe: &mut Safe,
    xorurl: &str,
    path: &Path,
    size: u64,
) -> Result<u64> {
    debug!("downloading file {} to {}", xorurl, path.display());

    // TODO: download the file by concurrently (spawning tasks/threads) pulling chunks.
    // The chunk_size can be based on https://stackoverflow.com/questions/8803515/optimal-buffer-size-for-write2
    // which can be 4096 to match common disk block size, but that seems a bit small for the
    // network, so I multiplied by 16. Perhaps should make it a param so caller can decide.
    let mut rcvd: u64 = 0;
    let mut bytes_written: u64 = 0;

    let fh = file_create(path)?;
    let mut stream = BufWriter::new(fh);

    // gets public or private, based on xorurl type
    let filedata = files_get_blob(safe, xorurl, None).await?;
    bytes_written += stream_write(&mut stream, &filedata, path)? as u64;
    rcvd += filedata.len() as u64;
    trace!("received {} bytes of {}", rcvd, size,);

    // Close may generate an error, so we do a flush/sync first to detect such.
    // see https://github.com/rust-lang/rust/pull/63410#issuecomment-519965351
    let fh = bufwriter_into_inner(stream, path)?;
    file_sync_all(&fh, path)?;

    Ok(bytes_written as u64)
}
// Downloads a file from the network to a given file path
// xorurl must point to a Blob
// size (in bytes) must be provided
Downloads a file from the network to a given file path
xorurl must point to a Blob
size (in bytes) must be provided
Downloads a file from the network to a given file path xorurl must point to a Blob size ( in bytes ) must be provided
async fn download_file_from_net(
    safe: &mut Safe,
    xorurl: &str,
    path: &Path,
    size: u64,
) -> Result<u64> {
    debug!("downloading file {} to {}", xorurl, path.display());
    // TODO: download the file by concurrently (spawning tasks/threads) pulling chunks.
    // The chunk_size can be based on https://stackoverflow.com/questions/8803515/optimal-buffer-size-for-write2
    // which can be 4096 to match common disk block size, but that seems a bit small for the
    // network, so I multiplied by 16. Perhaps should make it a param so caller can decide.
    let mut rcvd: u64 = 0;
    let mut bytes_written: u64 = 0;
    let fh = file_create(path)?;
    let mut stream = BufWriter::new(fh);
    // gets public or private, based on xorurl type
    let filedata = files_get_blob(safe, xorurl, None).await?;
    bytes_written += stream_write(&mut stream, &filedata, path)? as u64;
    rcvd += filedata.len() as u64;
    trace!("received {} bytes of {}", rcvd, size,);
    // Close may generate an error, so we do a flush/sync first to detect such.
    // see https://github.com/rust-lang/rust/pull/63410#issuecomment-519965351
    let fh = bufwriter_into_inner(stream, path)?;
    file_sync_all(&fh, path)?;
    Ok(bytes_written as u64)
}
async fn download_file_from_net ( safe : & mut Safe , xorurl : & str , path : & Path , size : u64 , ) -> Result < u64 > { debug ! ( " " xorurl path display ( ) ) ; // TODO: download the file by concurrently (spawning tasks/threads) pulling chunks. // The chunk_size can be based on https://stackoverflow.com/questions/8803515/optimal-buffer-size-for-write2 // which can be 4096 to match common disk block size, but that seems a bit small for the // network, so I multiplied by 16. Perhaps should make it a param so caller can decide. let mut rcvd : u64 = 0 ; let mut bytes_written : u64 = 0 ; let fh = file_create ( path ) ? ; let mut stream = BufWriter :: new ( fh ) ; // gets public or private, based on xorurl type let filedata = files_get_blob ( safe , xorurl , None ) . await ? ; bytes_written += stream_write ( & mut stream , & filedata , path ) ? as u64 ; rcvd += filedata . len ( ) as u64 ; trace ! ( " " rcvd size ) ; // Close may generate an error, so we do a flush/sync first to detect such. // see https://github.com/rust-lang/rust/pull/63410#issuecomment-519965351 let fh = bufwriter_into_inner ( stream , path ) ? ; file_sync_all ( & fh , path ) ? ; Ok ( bytes_written as u64 ) }
Downloads a file from the network to a given file path
xorurl must point to a Blob
size (in bytes) must be provided
Downloads a file from the network to a given file path xorurl must point to a Blob size ( in bytes ) must be provided
safe
&mut Safe
xorurl
&str
path
&Path
size
u64