Add ability to write archives to stdout
This commit is contained in:
parent
9938e7252a
commit
ce1c383f44
@ -40,3 +40,5 @@ to see Haggis implemented in other languages.
|
|||||||
- [x] Override user/group when extracting archives
|
- [x] Override user/group when extracting archives
|
||||||
- [x] Automatically detect zstd compressed archives
|
- [x] Automatically detect zstd compressed archives
|
||||||
- [ ] Add path to error message when passing between threads
|
- [ ] Add path to error message when passing between threads
|
||||||
|
- [x] Add ability to write archives to stdout
|
||||||
|
- [ ] Add ability to read archives from stdin
|
||||||
|
35
src/lib.rs
35
src/lib.rs
@ -3,7 +3,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fs,
|
fs,
|
||||||
io::{BufWriter, Read, Seek, Write},
|
io::{self, BufWriter, Read, Seek, Write},
|
||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "parallel")]
|
#[cfg(feature = "parallel")]
|
||||||
@ -72,6 +72,21 @@ pub fn create_archive(
|
|||||||
Ok(())
|
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<u32>,
|
||||||
|
gid: Option<u32>,
|
||||||
|
) -> 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`
|
/// Streams a haggis archive over something which implements `Write`
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Returns `crate::Error` if io fails or several other error conditions
|
/// Returns `crate::Error` if io fails or several other error conditions
|
||||||
@ -130,6 +145,24 @@ pub fn par_create_archive(
|
|||||||
Ok(())
|
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<Message>,
|
||||||
|
uid: Option<u32>,
|
||||||
|
gid: Option<u32>,
|
||||||
|
) -> 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
|
/// Streams a Haggis archive from a list of files, processing each file in parallel
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// Returns `crate::Error` if io fails or several other error conditions
|
/// Returns `crate::Error` if io fails or several other error conditions
|
||||||
|
Loading…
Reference in New Issue
Block a user