pub fn extract<S: Read + Seek>(
source: S,
target_dir: &Path,
strip_toplevel: bool,
) -> Result<(), ZipExtractError>
Expand description
Extracts a zip archive into target_dir
.
target_dir
is created if it doesn’t exist. Will error if target_dir.parent()
doesn’t exist.
If strip_toplevel
is true, will strip away the topmost directory. strip_toplevel
only applies
if all files and directories within the archive are descendants of the toplevel directory.
If you want to read from a source that doesn’t implement Seek, you can wrap it into a Cursor:
use std::io::Cursor;
use std::path::PathBuf;
let bytes: Vec<u8> = vec![];
let target = PathBuf::from("/tmp/target-directory");
zip_extract::extract(Cursor::new(bytes), &target, false);
If on unix, extract
will preserve permissions while extracting.