Commit graph

178 commits

Author SHA1 Message Date
Mathijs van de Nes
bb38674a14 Add archive_offset after processing extra fields
This ensures that the value will still be 0xFFFFFFFF before parsing a
zip64 extra field, and that the correction will also apply after the
parsing.
2018-10-17 11:45:41 +02:00
Mathijs van de Nes
c286a8ba16 Zip64: also support a large header_start 2018-10-17 11:39:15 +02:00
Mathijs van de Nes
a1d579b146 Silence warnings about AsciiExt
Some supported rust versions still require this import
2018-10-16 17:47:48 +02:00
Mathijs van de Nes
dbb871245b Fix parse_extra_field for zip64
The specification states that fields are only present when their
corresponding entry in the central directory is set to 0xFFFFFFFF.
2018-10-16 17:44:53 +02:00
Benedikt Rascher-Friesenhausen
804cfea51c Replace try! macros with ? operator calls
The `?` operator exists since Rust version 1.13.0 and has since become the
standard and recommended variant over the `try!` macro (see
https://doc.rust-lang.org/std/macro.try.html where it is explicitly mentioned to
use the `?` operator instead of the `try!` macro).

I think it is especially useful to replace the `try!` usages throughout the
examples (since new users might not be familiar with the `try!` macro at all).
2018-10-02 23:12:35 +02:00
Mathijs van de Nes
b23200d4a1 Append a slash to directory names
If a directory name does not end with a slash, append it to it when
writing a zip file. This way we can ensure it is distuinguishable from
an empty file.
2018-08-15 21:54:24 +02:00
Mathijs van de Nes
1c2024c554 Derivce Clone for ZipArchive 2018-06-22 15:47:29 +02:00
Mathijs van de Nes
2fa4111042 Fix an issue parsing zip64 files
Offset to the start of central directory may be 0xFFFFFFFF if it is a
Zip64 file. Previously, that value was used when calculating the archive
offset. The value will now be ignored if the Zip64 central directory
could be located.
2018-06-22 15:16:04 +02:00
Johan Andersson
0b222aa958 Remove redundant type specification 2018-06-20 01:38:43 +02:00
Johan Andersson
d51a4fc1d0 Fix file name sanitization for incompatible path separators.
Zip files can contain both / and \ as separators regardless of the OS and as we want to return a sanitized PathBuf that only supports the OS separator on the let's convert incompatible separators to compatible ones.

If one doesn't do this then PathBufs will be returned that can have entire paths in the file name such as "src\\lib.rs" on Linux/Mac, instead of srv / lib.rs as 3 separate components.
2018-06-20 01:31:46 +02:00
Mathijs van de Nes
86d9d20884 Calculate data_start after parse_extra_field
Some extra fields may alter offsets, e.g. Zip64.
2018-06-17 15:23:19 +02:00
Mathijs van de Nes
d2ccfc16f7 Speed up Drop of ZipFileReader
Skip CRC and decompression when dropping an owned ZipFileReader
2018-06-17 15:16:14 +02:00
Mathijs van de Nes
38d1699853 Improve reading from non-seekable streams
You can now repeatedly call a function to iterate over all files in a
zip. This may give some suboptimal results, but is useful when dealing
with an incoming data stream.
2018-06-16 14:14:34 +02:00
Mathijs van de Nes
5b17e07086 Merge branch 'sequential-read' of https://github.com/FauxFaux/zip-rs into FauxFaux-sequential-read 2018-06-15 16:59:09 +02:00
Mathijs van de Nes
39ccaab76c Merge branch 'flate2-backends' of https://github.com/alexbool/zip-rs 2018-05-27 10:33:52 +02:00
Mathijs van de Nes
1cb79a0b91 Fix memory issues on corrupt zip files
Do not pre-allocate the number of files, as this might be an invalid
number.

Also give a more helpfull error message when the start of the central
directory could not be found.

Resolves #68
2018-05-23 19:43:46 +02:00
Mathijs van de Nes
00310c44d8 Expose zip file comment in ZipArchive
Resolves #71
2018-05-23 19:17:06 +02:00
Mathijs van de Nes
602952750e Update DEFAULT_VERSION
Use a more sane 'version made by' as we can write Bzip2 files
2018-05-22 23:36:56 +02:00
Mathijs van de Nes
ab9667aa5c Properly write 'version needed' in local file header
'version made by' was used instead of version needed by accident.

Resolves #72
2018-05-22 23:36:56 +02:00
Alexander Bulaev
fee626ba59 Control backend choice of flate2 2018-05-19 20:03:23 +03:00
Mathijs van de Nes
806147ac9e Fix sanitized_name test for Windows 2018-04-20 13:53:07 +02:00
Mathijs van de Nes
5e8c95e6ed Make santized_name part of the library
It is a common pitfall to use the name as-is during extraction. Adding
this function may prevent some of the issues.

Resolves #65
2018-04-20 13:35:20 +02:00
Mathijs van de Nes
fce3836059 Better handling of zips with invalid datetimes
The msdos datetime 0x00000000 is invalid. The Windows API would
(rightfully) return an ERROR_INVALID_PARAMETER for this when converting
it. If it is indeed an invalid error, we now return the zip datetime
'epoch' of 1980-01-01 00:00:00.

Resolves issue #61
2018-02-17 20:05:09 +01:00
Mathijs van de Nes
b2db9d55ae Merge branch 'deflate_feature' of https://github.com/jhwgh1968/zip-rs 2018-01-09 18:38:27 +01:00
Danilo Bargen
2469419a89 Fix compatibility with Rust <1.23 2018-01-08 08:26:49 +01:00
jhwgh1968
7c2d4e2901 Named the deflate algorithm feature gate "deflate" 2018-01-07 13:39:42 -06:00
jhwgh1968
19274b497a Made deflate compression into separate feature 2018-01-07 00:47:11 -06:00
Mathijs van de Nes
bbb279286a Remove unused import 2018-01-06 12:06:23 +01:00
rardiol
22194687c6 use flate2 1.0 2018-01-01 17:12:41 -03:00
Robin Syihab
c99d7c2758
Handle invalid zip header 2017-12-04 01:19:44 +07:00
Peter Williams
f85b5cb7b8 Add a test for ZIP64 with leading junk.
I constructed this file using a hack from the Zip manpage: if the input to a
Zip compression command is streamed on standard input, the output is given in
ZIP64 format since the tool doesn't know how big the input will be. I modified
the resulting file by adding some leading junk text and editing the non-ZIP64
end-of-central-directory structure to have 0xFFFF for its "number of files"
parameters, to help the test demonstrate that the ZIP64 data are being
properly read. (0xFFFF is the value used in the non-ZIP64 structure if the
archive actually has more than 65535 files.)
2017-08-12 14:42:32 -04:00
Peter Williams
4a297c32a8 Implement support for reading ZIP64 central-directory-end records
This provides only very basic ZIP64 support, but it allows us to properly read
archives with more than 65535 files, so long as none of the individual files
need ZIP64 support to be read.
2017-08-12 14:42:32 -04:00
Peter Williams
89f33c9348 Use u64's for internal file offsets.
These are better aligned with Rust's APIs, and lay the groundwork for more
convenient support of Zip64 files.
2017-08-12 14:42:32 -04:00
Mathijs van de Nes
2dae0d4a5c Add regression test for #40 2017-07-05 21:36:47 +02:00
Pascal Hertleif
57a6514a40 Prevent subtract with overflow
This changes assumes this only happens when the archive is invalid.

Fixes #40
2017-06-27 11:23:17 +02:00
Mathijs van de Nes
7aaedf6457 Add Copy/Clone for FileOptions
Resolves #38
2017-05-28 12:26:18 +02:00
Mathijs van de Nes
afb306d11d Merge branch 'feature/data-start' of https://github.com/bbqsrc/zip-rs 2017-04-28 12:43:03 +02:00
Mathijs van de Nes
240e1d469d Corrected some static -> const 2017-04-28 10:31:12 +02:00
Chris West (Faux)
0b5746150c read_single 2017-04-24 15:12:22 +01:00
Brendan Molloy
60596d15d9 Add data_start property to ZipFile 2017-04-17 15:53:10 +10:00
Stephen M. Coakley
fc746a09db
Handle data prepended to the zip 2017-04-08 03:04:18 -05:00
Mathijs van de Nes
633360a5a7 Ignore Io errors in extra field
IoErrors mean that the extra field was not long enough or contained an invalid lenght value.
These are ignored for now.

Resolves #32
2017-03-30 19:18:08 +02:00
Mathijs van de Nes
236050947a Fix a regression
Test would not compile anymore... weird
2017-03-30 19:03:25 +02:00
Jos van den Oever
93f676fa57 Add two simple tests. 2017-03-14 20:16:51 +01:00
Mihai STAN
7d85d8fb66 Fix writing to buffers.
Using SeekFrom::End(0) in finish_file for a buffer was movind the position
the the end of the buffer, not the last written byte.
2017-03-06 06:22:42 +02:00
Mathijs van de Nes
1831edbbdd 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
2017-02-12 17:18:40 +01:00
Mathijs van de Nes
d2d19f6539 Update the write API
This change adds a FileOptions struct. This struct can be filled using a builder pattern
to set the options for a file or folder.

With this change, we also introduce the option to set the (unix) permissions of a file or folder.
2016-10-30 09:09:50 +01:00
Mathijs van de Nes
82315c9511 Add comments to write.rs
Clarify which field means what when writing structures
2016-10-29 12:30:59 +02:00
Mathijs van de Nes
49e506c13c Fix types::System enum
Unix had incorrectly assigned the value 1 instead of 3
2016-10-29 12:30:30 +02:00
Don Rowe
1075ebf5f4 Add test for Display implementation for CompressionMethod 2016-10-03 21:34:14 -07:00