2 unstable releases
0.1.0 | Feb 1, 2023 |
---|---|
0.0.2 | Jan 31, 2023 |
#519 in Compression
13KB
238 lines
path-with-zip
Ex version of PathBuf in Rust.
Examples below assume that there is a 'test.zip' in the same directory of this executable program file.
(Root of 'test.zip') |---test(Folder) |---test.txt(File)
Example: Reading a file in a zip archive
use path_with_zip::PathBufWithZip;
let path = "test.zip///test/test.txt";
// The error type is zip::result::ZipError, which includes std::io::Error.
let bytes: Vec<u8> = PathBufWithZip::from(path).read_bytes_directly().unwrap();
Another way:
use path_with_zip::PathBufWithZip;
let path = "test.zip///test/test.txt";
let pathbuf_with_zip = PathBufWithZip::from(path);
let mut zip_archive = pathbuf_with_zip.open_archive().unwrap();
// OR
// let mut zip_archive = pathbuf_with_zip.open_archive_into_memory().unwrap();
let bytes: Vec<u8> = pathbuf_with_zip.read_bytes(Some(&mut zip_archive)).unwrap();
Example: Reading a file like using PathBuf
use path_with_zip::PathBufWithZip;
let path = "test.zip";
let bytes: Vec<u8> = PathBufWithZip::from(path).read_bytes_directly().unwrap();
Another way:
use path_with_zip::PathBufWithZip;
let path = "test.zip";
let pathbuf_with_zip = PathBufWithZip::from(path);
let bytes: Vec<u8> = pathbuf_with_zip.read_bytes(None).unwrap();
Dependencies
~5MB
~86K SLoC