Commit Graph

78 Commits

Author SHA1 Message Date
Robert Haines f033ae760d Use named parameters for `File::new`.
This is a breaking change, but now is the time to do this as we've
already done the same for `Entry::new`.
2021-06-27 10:20:11 +01:00
Robert Haines e1e1cab39c Fix some non-writable `StringIO`s. 2021-06-27 10:20:11 +01:00
Robert Haines f1e8c2fc9d Fix Style/StringConcatenation cop. 2021-06-18 16:10:57 +01:00
Jan-Joost Spanjers 8a24bff1b2 Disable recover file permissions test on Windows 2021-06-06 14:44:20 +01:00
Jan-Joost Spanjers c3443c06ea Make recover file permissions test better understandable 2021-06-06 14:44:20 +01:00
Jan-Joost Spanjers 0051d5bb1f Read/write test files in binay mode (for Windows compatibility) 2021-06-06 14:44:20 +01:00
Robert Haines dea45613bb Test non-block version of File#get_output_stream. 2021-05-25 22:23:39 +01:00
Robert Haines ed21f9cf17 Fix Performance/StringInclude cop. 2021-05-25 21:24:50 +01:00
Robert Haines e2c16991e5 Fix Style/Dir cop. 2021-05-25 21:24:50 +01:00
Robert Haines deac4fa313 Fix Style/CommentAnnotation cop. 2021-05-25 21:24:50 +01:00
Robert Haines e10badf68e Fix Style/FrozenStringLiteralComment cop. 2021-05-25 21:24:50 +01:00
Taichi Ishitani 0e4dc676a0 fix frozen string literal error 2021-05-25 21:24:50 +01:00
Robert Haines 9da6be98d8 Fix the compression level tests to be relative.
Made little sense to use hardcoded bytes sizes; the tests end up too
brittle.
2021-02-16 13:21:24 +00:00
Robert Haines e4ceedaa58 Use keyword arguments for the `Entry` initializer.
This greatly simplifies the creation of `Entry` objects when only a
couple of fields are not set to their defaults, while at the same time
allowing an `Entry` to be fully configured at creation time if
appropriate.

This fundamentally changes the `Entry` API and  means that some
convenience methods in `OutputStream` and `File` have needed to be
refactored.
2020-08-31 17:48:08 +01:00
Robert Haines d4bc24dcb3 Clean up `OutputStream` internals.
There was some fairly odd stuff going on in `put_next_entry` that
allowed for data within an `Entry` to be overridden and prevented an
`Entry` from being a single point of truth. Fixing this also simplifies
the code within `File` and still passes all tests.

Also, fixing the above means we can stop passing the compression level
around as a parameter and use the value stored in each `Entry` directly.

Let's keep `compression_level` out of the `Entry` public API though as
it only makes sense when writing an `Entry`: there doesn't seem to be an
obvious way to read what level of compression was used when reading an
`Entry` from a zip file.
2020-08-31 17:48:08 +01:00
Robert Haines 14451e63e7 Add setting a compression level to the File options.
It looks like it needs to be surfaced in `add` and `get_output_stream`.
The compression level defaults to whatever the global default is unless
it is overridden on opening the Zip::File.

Also needed to reorder some of the requires in the top-level module file
now that we are using defaults in the File class.
2020-08-31 17:48:08 +01:00
Robert Haines ef520b4b94 Add `compression_level` to the Entry API.
Allow an Entry to specify a compression level and pass this down to the
underlying OutputStream infrastructure. OutputStream has been able to
specify a compression level for a while but this has, up until now, only
ever been set to the default.

This fundamentally changes the API so will need a major version bump.
2020-08-31 17:48:08 +01:00
Robert Haines e6f414f539 Fix Naming/VariableName cop in the tests. 2020-02-29 18:11:52 +00:00
Robert Haines b09f05d8d3 Fix Naming/MethodParameterName cop in the tests. 2020-02-29 18:11:52 +00:00
Robert Haines 0df6cb3059 Fix Style/SymbolProc cop. 2020-02-15 16:26:32 +00:00
Robert Haines 2e11a88fd2 Fix Style/StringLiterals cop. 2020-02-15 16:26:32 +00:00
Robert Haines b3c4c37882 Fix Style/NonNilCheck cop.
Use the `refute_nil` method for most of these.
2020-02-15 16:26:32 +00:00
Robert Haines cfe4972e71 Fix Layout/EmptyLineAfterGuardClause cop. 2020-02-15 16:26:32 +00:00
Robert Haines cd065d0186 Fix Lint/UnusedBlockArgument cop. 2020-02-15 16:26:32 +00:00
Robert Haines 3a3ac6feb7 Fix Style/Semicolon cop. 2020-02-15 16:26:32 +00:00
Robert Haines f3a2f4a8ec Add tests for File#get/find_entry. 2019-10-31 18:15:17 +00:00
John Lees-Miller 93505ca16f Check expected entry size in add_stored test 2019-09-15 14:58:13 +01:00
Robert Haines ecb2776218 Zip::File.add_stored() to add uncompressed files.
Adding uncompressed files to a zip archive can be overly complex, so
this convenience method makes it easier.
2019-09-14 13:58:30 +01:00
John Lees-Miller 9a41ce65c4 Add more explicit test for #280 2019-09-06 17:58:38 +01:00
John Lees-Miller eeef5073d5 Add test case based on #146 2019-09-05 19:00:34 +01:00
John Lees-Miller 7fbaf1e6c0
Merge pull request #360 from hainesr/fix-open-buffer
Fix #280 - `open_buffer` mangles the content of the buffer it is given.
2019-09-05 18:48:39 +01:00
Oleksandr Simonov 8887b70349
Merge pull request #361 from hainesr/quiet-tests
Turn off all terminal output in all tests.
2018-04-23 22:18:31 +03:00
Robert Haines cd7bb142a4 Turn off all terminal output in all tests.
Makes things a lot easier when trying to track down bugs.
2018-04-04 19:45:54 +01:00
Robert Haines 84c208982f Switch newly created StringIOs to binmode.
StringIO objects created within File.open_buffer were not being switched into
binmode, but those passed in were. Fix this inconsistency and add a test.
2018-04-04 16:02:19 +01:00
Robert Haines 15ccc25da1 Fix File.open_buffer when no changes are made.
Things are now more carefully set up, and if a buffer is passed in which
represents a file that already exists then this is taken into account. All
initialization is now done in File.new, rather than being split between there
and File.open_buffer.

This has also needed a bit of a re-write of Zip::File.initialize. I've tried to
bring some logic to it as a result, and have added comments to explain what is
now happening.
2018-04-04 15:54:12 +01:00
Andrew Meyer c787d94852 Handle stored files with general purpose bit 3 set
Signed-off-by: Sam Coward <scoward@pivotal.io>
2018-04-03 16:07:18 -04:00
Phil 792266dbf3 Added fix for calling 'close' on a StringIO-backed zip file, and specs 2018-02-21 11:48:56 -08:00
Takumasa Ochi cf91112b57 Apply automatic correction by rubocop 2017-06-29 11:57:12 +09:00
mwlang 14b8fed18c allows open_buffer to work without a given block 2017-01-16 13:24:22 -06:00
David Rodríguez f157dfc1b6 Revert "Cleanup after ourselves"
This reverts commit 6597af1257 since
7caab1f already fixed the same thing. It should fix the build.
2016-11-10 08:23:34 -02:00
Alexander Simonov a0cf673186 Merge pull request #300 from hainesr/fix-create-perms
Fix permissions on new zip files (#294)
2016-11-09 22:19:04 +02:00
Alexander Simonov 82fa57cc83 Merge pull request #303 from deivid-rodriguez/extended_globbing
Extended globbing
2016-11-09 22:17:17 +02:00
David Rodríguez 6597af1257 Cleanup after ourselves
Otherwise tests leave an empty file there.
2016-10-08 19:23:45 -03:00
David Rodríguez 366a1d8dca Fix test failure when running a single test file
```
bundle exec rake TEST=test/file_test.rb
```

was giving

```
  1) Error:
ZipFileTest#test_get_output_stream:
NameError: uninitialized constant ZipFileTest::ZipEntryTest
    .../test/file_test.rb:59:in `block in test_get_output_stream'
    .../lib/zip/file.rb:102:in `open'
    .../test/file_test.rb:45:in `test_get_output_stream'
```
2016-10-08 19:21:30 -03:00
Robert Haines fc23f68f77 Refactor the create logic in Zip::File.
Make the internal @create varible more consistent and actually match the
documentation.

Zip::File::CREATE is now true, rather than 1.

A new test is added to check if passing 1 in still works to ensure backwards
compatibility.
2016-09-05 15:16:57 +01:00
Robert Haines 7caab1f467 Clean up empty.zip after running tests.
After running the tests there was a file left in the project directory,
'empty.zip', which was simply 'touch'ed to use as a null file. Switch to create
this as one of the generated test files so it's cleaned up automatically.

Also, use 'null.zip' as the name as there is already an 'empty.zip' generated
that is a zip file, but empty.
2016-08-28 12:17:17 +01:00
Oleksandr Avoiants 73bfa5955c Fix TypeError: can't dup NilClass from EntrySet#dup 2015-12-19 11:26:20 +02:00
Victor Costan 77acc03ddb Fix exception due to calling empty? on nil. 2015-09-30 03:57:21 -04:00
Claire Pitman a1f75a3ab9 Added error for empty (zero bit) zip file. Added tests for empty and non existant zips 2015-07-27 23:20:59 -07:00
Victor Costan 37a5baad96 Accept StringIO in Zip.open_buffer. 2015-07-02 14:17:17 -04:00