diff --git a/README.md b/README.md index 3d12287..d7d6b1e 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,5 @@ to see Haggis implemented in other languages. - [x] Override user/group when extracting archives - [x] Automatically detect zstd compressed archives - [ ] Add path to error message when passing between threads +- [x] Add ability to write archives to stdout +- [ ] Add ability to read archives from stdin diff --git a/src/lib.rs b/src/lib.rs index 1e00ae8..4e9fdf8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ use std::{ collections::HashMap, fs, - io::{BufWriter, Read, Seek, Write}, + io::{self, BufWriter, Read, Seek, Write}, sync::Mutex, }; #[cfg(feature = "parallel")] @@ -72,6 +72,21 @@ pub fn create_archive( Ok(()) } +/// Creates a haggis archive and writes it to stdout +/// # Errors +/// Returns `crate::Error` if io fails +pub fn create_archive_stdout( + files: &[String], + algorithm: Algorithm, + uid: Option, + gid: Option, +) -> Result<(), Error> { + let stdout = io::stdout().lock(); + let mut writer = BufWriter::new(stdout); + stream_archive(&mut writer, files, algorithm, uid, gid)?; + Ok(()) +} + /// Streams a haggis archive over something which implements `Write` /// # Errors /// Returns `crate::Error` if io fails or several other error conditions @@ -130,6 +145,24 @@ pub fn par_create_archive( Ok(()) } +/// Creates a Haggis archive from a list of file, processing each file in parallel +/// and writing the resulting archive to stdout +/// # Errors +/// Returns `crate::Error` if io fails of one of several other conditions +#[cfg(feature = "parallel")] +pub fn par_create_archive_stdout( + files: &[String], + algorithm: Algorithm, + sender: &Sender, + uid: Option, + gid: Option, +) -> Result<(), Error> { + let stdout = io::stdout().lock(); + let writer = BufWriter::new(stdout); + par_stream_archive(writer, files, algorithm, uid, gid)?; + Ok(()) +} + /// Streams a Haggis archive from a list of files, processing each file in parallel /// # Errors /// Returns `crate::Error` if io fails or several other error conditions