Crates.io | path-with-zip |
lib.rs | path-with-zip |
version | 0.1.0 |
source | src |
created_at | 2023-01-31 15:20:26.010193 |
updated_at | 2023-02-01 07:04:04.753352 |
description | A PathBuf-like struct for zip archive use. |
homepage | |
repository | https://gitee.com/MiyakoMeow/path-with-zip |
max_upload_size | |
id | 772762 |
size | 14,922 |
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)
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();
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();