Expose the raw file name of a file
We still do most operations with normal Strings, but a user can now also get the raw bytes. Resolves #26
This commit is contained in:
parent
88445219ec
commit
1831edbbdd
5 changed files with 14 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
|
||||
name = "zip"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
authors = ["Mathijs van de Nes <git@mathijs.vd-nes.nl>"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/mvdnes/zip-rs.git"
|
||||
|
|
|
@ -39,7 +39,7 @@ fn real_main() -> i32
|
|||
|
||||
if (&*file.name()).ends_with("/") {
|
||||
create_directory(&outpath, perms);
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
write_file(&mut file, &outpath, perms);
|
||||
|
|
|
@ -212,7 +212,7 @@ fn central_header_to_zip_file<R: Read+io::Seek>(reader: &mut R) -> ZipResult<Zip
|
|||
let file_name = match is_utf8
|
||||
{
|
||||
true => String::from_utf8_lossy(&*file_name_raw).into_owned(),
|
||||
false => file_name_raw.from_cp437(),
|
||||
false => file_name_raw.clone().from_cp437(),
|
||||
};
|
||||
let file_comment = match is_utf8
|
||||
{
|
||||
|
@ -249,6 +249,7 @@ fn central_header_to_zip_file<R: Read+io::Seek>(reader: &mut R) -> ZipResult<Zip
|
|||
compressed_size: compressed_size as u64,
|
||||
uncompressed_size: uncompressed_size as u64,
|
||||
file_name: file_name,
|
||||
file_name_raw: file_name_raw,
|
||||
file_comment: file_comment,
|
||||
header_start: offset,
|
||||
data_start: data_start,
|
||||
|
@ -297,6 +298,10 @@ impl<'a> ZipFile<'a> {
|
|||
pub fn name(&self) -> &str {
|
||||
&*self.data.file_name
|
||||
}
|
||||
/// Get the name of the file, in the raw (internal) byte representation.
|
||||
pub fn name_raw(&self) -> &[u8] {
|
||||
&*self.data.file_name_raw
|
||||
}
|
||||
/// Get the comment of the file
|
||||
pub fn comment(&self) -> &str {
|
||||
&*self.data.file_comment
|
||||
|
|
|
@ -49,6 +49,8 @@ pub struct ZipFileData
|
|||
pub uncompressed_size: u64,
|
||||
/// Name of the file
|
||||
pub file_name: String,
|
||||
/// Raw file name. To be used when file_name was incorrectly decoded.
|
||||
pub file_name_raw: Vec<u8>,
|
||||
/// File comment
|
||||
pub file_comment: String,
|
||||
/// Specifies where the local header of the file starts
|
||||
|
|
|
@ -178,6 +178,8 @@ impl<W: Write+io::Seek> ZipWriter<W>
|
|||
let header_start = try!(writer.seek(io::SeekFrom::Current(0)));
|
||||
|
||||
let permissions = options.permissions.unwrap_or(0o100644);
|
||||
let file_name = name.into();
|
||||
let file_name_raw = file_name.clone().into_bytes();
|
||||
let mut file = ZipFileData
|
||||
{
|
||||
system: System::Unix,
|
||||
|
@ -188,7 +190,8 @@ impl<W: Write+io::Seek> ZipWriter<W>
|
|||
crc32: 0,
|
||||
compressed_size: 0,
|
||||
uncompressed_size: 0,
|
||||
file_name: name.into(),
|
||||
file_name: file_name,
|
||||
file_name_raw: file_name_raw,
|
||||
file_comment: String::new(),
|
||||
header_start: header_start,
|
||||
data_start: 0,
|
||||
|
|
Loading…
Add table
Reference in a new issue