-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rust): introduce a new "transfer" module
* This module replaces the old "download" function.
- Loading branch information
Showing
5 changed files
with
50 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! File transfer API for Agama. | ||
//! | ||
//! Implement a file transfer API which, in the future, will support Agama specific URLs. Check the | ||
//! YaST document about [URL handling in the | ||
//! installer](https://github.com/yast/yast-installation/blob/master/doc/url.md) for further | ||
//! information. | ||
//! | ||
//! At this point, it only supports those schemes supported by CURL. | ||
use std::io::Write; | ||
|
||
use curl::easy::Easy; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
#[error(transparent)] | ||
pub struct TransferError(#[from] curl::Error); | ||
pub type TransferResult<T> = Result<T, TransferError>; | ||
|
||
/// File transfer API | ||
pub struct Transfer {} | ||
|
||
impl Transfer { | ||
/// Retrieves and writes the data from an URL | ||
/// | ||
/// * `url`: URL to get the data from. | ||
/// * `out_fd`: where to write the data. | ||
pub fn get(url: &str, mut out_fd: impl Write) -> TransferResult<()> { | ||
let mut handle = Easy::new(); | ||
handle.url(url)?; | ||
|
||
let mut transfer = handle.transfer(); | ||
transfer.write_function(|buf| Ok(out_fd.write(buf).unwrap()))?; | ||
transfer.perform()?; | ||
Ok(()) | ||
} | ||
} |