Commit Graph

80 Commits

Author SHA1 Message Date
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 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 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 f9b161eb32 Fix Naming/VariableName cop in the library code. 2020-02-29 18:11:52 +00:00
Robert Haines aa6ea05d45 Fix Naming/MethodParameterName cop in the library code. 2020-02-29 18:11:52 +00:00
Robert Haines 846e704048 Fix Naming/BlockParameterName cop. 2020-02-17 22:35:08 +00:00
Robert Haines 5ce4e13ddd Configure and fix Style/ClassCheck cop. 2020-02-15 16:26:32 +00:00
Robert Haines 6cab5922bc Configure and fix Metrics/LineLength cop.
Set a workable line length for now, and fix a couple of particularly bad
examples.

Also, turn off for the tests.
2020-02-15 16:26:32 +00:00
Robert Haines 0df6cb3059 Fix Style/SymbolProc cop. 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 98c6969c18 Fix Layout/SpaceAroundOperators cop. 2020-02-15 16:26:32 +00:00
Robert Haines 73e405acef Fix Security/Open cop errors. 2020-02-15 15:56:17 +00:00
Jan-Joost Spanjers 4e28f7286c Untangle encryption and decompression 2020-01-26 15:34:17 +01:00
Robert Haines 2d6b6e024b Ensure File#get/find_entry work consistently.
I have switched around the logic somewhat so that `get_entry` calls
`find_entry` and raises an exception if it gets `nil` back.
2019-10-31 18:12:18 +00:00
Robert Haines 378293539d Make the attr_accessors in File more readable.
Note what the default is and that a couple of them will change at some
point soon.
2019-10-19 20:46:21 +01:00
Robert Haines 253457545e Correctly set/default options in the File class.
Fixes #395. Set the options to false for now for consistency.
2019-10-19 20:45:29 +01:00
Robert Haines 3fea9958c2 Update comment for `Zip::File.open`. 2019-10-19 07:15:51 +01:00
Robert Haines f58e38012c Add the `options` parameter to `Zip::File.open`. 2019-10-19 07:04:04 +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
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
Robert Haines 03633933eb No need to require stringio in Zip::File.open_buffer.
It's already required in zip.rb.
2018-04-04 14:31:34 +01:00
Robert Haines cfa9441914 Handle passing an IO to Zip::File.new better.
This now actually extracts the path from the IO if one is passed in.
2018-04-03 23:48:54 +01:00
Robert Haines 7cd263e6a0 Clean up use of file_name in Zip::File::initialize. 2018-04-03 23:45:04 +01: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
Robert Haines c00d767533 Fix rubocop offence caused by temp files changes. 2016-09-05 17:34:12 +01: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 63ed0d970b Refactor the code which manages temp files.
Combine the creation of the temporary filename with the writing to it.
2016-09-05 15:07:18 +01:00
Robert Haines 7b14d11c00 Stop using 0600 perms for temporary files.
This fixes #294 in what I hope is a more sensible way than trying to mess with
umasks, etc, directly.

Temporary files were being created with 0600 permissions and then being set to
different permissions, based on umask, etc, afterwards. I don't know what the
rationale for this was, but there were errors in the umask calculations when
moving from the temporary file to the intended end result.
2016-09-01 12:10:56 +01:00
Mike Naberezny 6e1dea4f66 Fix accidental unlink (#185) without using ObjectSpace (#252) 2015-11-22 14:40:59 -08:00
Alexander Simonov 8447f0e230
Fix #252 2015-11-21 12:07:30 +02:00
Seth Kingsley 05a9ba3f20 Use duck typing to detect IO-like objects. 2015-09-03 06:16:32 -07: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
Robert Haines 9acc50f004 Do something more expected with new file permissions.
Instead of inheriting the permissions from the tmp directory, new files should
have permissions that reflect the defaults on the system taking umask into
account.

It seems that (unix) permissions of 666 - umask are as close to a standard as
anything [1] and that 'touch' uses this. On Windows it seems sensible to just
use 644 directly [2].

[1] http://unix.stackexchange.com/a/102080
[2] http://ruby-doc.org/core-1.9.3/File.html
2015-06-24 18:25:22 +01:00
Pavel Lobashov 1e99ff69b9 Revert "fix rubocop cop Style/ClassCheck". It cause regression in tests
This reverts commit 8c13dfc265.
2015-06-08 10:45:23 +03:00
Pavel Lobashov 8c13dfc265 fix rubocop cop Style/ClassCheck 2015-06-08 10:36:41 +03:00
Pavel Lobashov f7eec2dd76 fix rubocop cop Style/SpaceAroundOperators 2015-06-08 10:26:13 +03:00
Pavel Lobashov c0177a455b Merge branch 'master' into rubocop_fixes
Conflicts:
	README.md
	samples/example_recursive.rb
2015-06-08 10:14:25 +03:00
Vít Ondruch 32016ab1bf Remove executable bit. 2015-03-31 13:15:46 +02:00
Pavel Lobashov 112a77de7c fix some Style/FormatString cop 2015-03-24 19:20:39 +03:00
Pavel Lobashov b920a1eb49 fix rubocop Style/GuardClause cop 2015-03-24 19:16:03 +03:00
Pavel Lobashov b9aefaffb5 fix rubocop Style/IfUnlessModifier cop 2015-03-24 19:09:22 +03:00
Pavel Lobashov 1ba81ff46f fix rubocop Style/NumericLiterals cop 2015-03-23 19:23:04 +03:00
Pavel Lobashov 31fb9d729b fix rubocop Style/PredicateName cop 2015-03-23 19:18:51 +03:00
Pavel Lobashov d5f79822c1 fix rubocop Style/LineEndConcatenation cop 2015-03-23 19:03:28 +03:00