-
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?
Conversation
Thanks! Looks like CI is failing though? |
use tar::Archive; | ||
use xz2::read::XzDecoder; | ||
|
||
fn unpack_tar_xz(archive_path: &PathBuf, dest: &PathBuf) { |
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
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 comment
The 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 Archive
could be passed XzDecoder
directly, and additionally we don't need fs::read
but rather the XzDecoder
could be passed the raw file.
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.
Just stumbled upon this and wondering if here the decompress/extract step has to happen in two phases
because there's no other way to archive.set_preserve_mtime(false);
if it were to happen in one phase ?
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.
I think you can just call that on archive
at any time after construction, and constructing an Archive
doesn't actually do any decompression until it's needed to do so.
|
||
// We've decompressed the .xz; now unpack the tar. | ||
let mut archive = Archive::new(&tar[..]); | ||
archive.unpack(dest).expect("Problem unpacking tar"); |
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 use ?
and other more idiomatic error handling techniques rather than .unwrap()
?
No description provided.