8000 Added tar.xz extraction example by David-OConnor · Pull Request #53 · alexcrichton/xz2-rs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

David-OConnor
Copy link

No description provided.

@alexcrichton
Copy link
Owner

Thanks! Looks like CI is failing though?

use tar::Archive;
use xz2::read::XzDecoder;

fn unpack_tar_xz(archive_path: &PathBuf, dest: &PathBuf) {
Copy link
Owner

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?

Copy link
Owner

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[..]);
Copy link
Owner

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.

Copy link

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 ?

Copy link
Owner

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");
Copy link
Owner

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()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0