-
Notifications
You must be signed in to change notification settings - Fork 54
Added tar.xz extraction example #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::{fs, io::Read, path::PathBuf}; | ||
use tar::Archive; | ||
use xz2::read::XzDecoder; | ||
|
||
fn unpack_tar_xz(archive_path: &PathBuf, dest: &PathBuf) { | ||
let archive_bytes = fs::read(archive_path).expect("Problem reading archive as bytes"); | ||
|
||
let mut tar: Vec<u8> = Vec::new(); | ||
let mut decompressor = XzDecoder::new(&archive_bytes[..]); | ||
decompressor.read_to_end(&mut tar).expect("Problem decompressing archive"); | ||
|
||
// We've decompressed the .xz; now unpack the tar. | ||
let mut archive = Archive::new(&tar[..]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that the decompress/extract step has to happen in two phases, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just stumbled upon this and wondering if here the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn mor 8D05 e. I think you can just call that on |
||
archive.unpack(dest).expect("Problem unpacking tar"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this use |
||
} | ||
|
||
fn main() { | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be called during the example to show off how it can be executed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that
&Path
is also more idiomatic than&PathBuf