path-with-zip

Crates.iopath-with-zip
lib.rspath-with-zip
version0.1.0
sourcesrc
created_at2023-01-31 15:20:26.010193
updated_at2023-02-01 07:04:04.753352
descriptionA PathBuf-like struct for zip archive use.
homepage
repositoryhttps://gitee.com/MiyakoMeow/path-with-zip
max_upload_size
id772762
size14,922
(MiyakoMeow)

documentation

https://docs.rs/path-with-zip/latest/path_with_zip/

README

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();
Commit count: 0

cargo fmt