zip_tricks 4.7.3 → 4.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 537945ff9983b6d84190281aaf71d52a265e49f5
4
- data.tar.gz: 1aa8b7a739b624dd7de4ea3e960d966f6f3d9ad3
3
+ metadata.gz: d1119a96243d5da6b423a2a3c992efc6fbb580fa
4
+ data.tar.gz: 63a1d0b2c93e5b231568e83efb60220862c07b7e
5
5
  SHA512:
6
- metadata.gz: 4a98133de0c4902de0babccb5ce5c59e97d9636e1191c65d61bdf538e58c3b81847871bee79584609fc1864f32a0b3dfb8068781149f5b957e43ad1ed80a8b35
7
- data.tar.gz: 42e5c29411a5b1a3942bf88f359694572fe0c4a3efbd61006457e0f53c5d0b9948bf8d5f7f801a5c819d341b2e6fc52f2479030c5dd9248b53e5f031faf65423
6
+ metadata.gz: 89c7300a0c3af8ceb0408d2c4315fc62e4abf5fecc53ca93219bf9ce30c146d9cc8bca193d35908f1d24516bc1298c12332850ff0352dd561ed67a56a6fe7211
7
+ data.tar.gz: 20cdfca60a6ac3cc5beaa57bf74dba06bd09ef18931931ddead388de68e6316650e4aad14fe96b7838b415babaafe9f8aa72ca5a9ccd547eb535f3e6f27901f4
data/.rubocop.yml CHANGED
@@ -7,4 +7,5 @@ Layout/FirstMethodParameterLineBreak:
7
7
  Style/GlobalVars:
8
8
  Exclude:
9
9
  - qa/*.rb
10
- - spec/spec_helper.rb
10
+ - spec/spec_helper.rb
11
+ - spec/support/zip_inspection.rb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 4.7.4
2
+
3
+ * Use a single fixed capacity string in StreamCRC32.from_io to avoid unnecessary allocations
4
+ * Fix a few tests that were calling out to external binaries
5
+
1
6
  ## 4.7.3
2
7
 
3
8
  * Fix RemoteUncap#request_object_size to function correctly
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2016 WeTransfer
1
+ Copyright (c) 2019 WeTransfer
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -30,7 +30,7 @@ The easiest is to use the Rails' built-in streaming feature:
30
30
  class ZipsController < ActionController::Base
31
31
  include ActionController::Live # required for streaming
32
32
  include ZipTricks::RailsStreaming
33
-
33
+
34
34
  def download
35
35
  zip_tricks_stream do |zip|
36
36
  zip.write_deflated_file('report1.csv') do |sink|
@@ -122,10 +122,10 @@ ZipTricks::Streamer.open(io) do | zip |
122
122
  # raw_file is written "as is" (STORED mode).
123
123
  # Write the local file header first..
124
124
  zip.add_stored_entry(filename: "first-file.bin", size: raw_file.size, crc32: raw_file_crc32)
125
-
125
+
126
126
  # then send the actual file contents bypassing the Streamer interface
127
127
  io.sendfile(my_temp_file)
128
-
128
+
129
129
  # ...and then adjust the ZIP offsets within the Streamer
130
130
  zip.simulate_write(my_temp_file.size)
131
131
  end
@@ -143,7 +143,7 @@ It is slightly more convenient for the purpose than using the raw Zlib library f
143
143
 
144
144
  ```ruby
145
145
  crc = ZipTricks::StreamCRC32.new
146
- crc << large_file.read(1024 * 12) until large_file.eof?
146
+ crc << next_chunk_of_data
147
147
  ...
148
148
 
149
149
  crc.to_i # Returns the actual CRC32 value computed so far
@@ -152,6 +152,12 @@ crc.to_i # Returns the actual CRC32 value computed so far
152
152
  crc.append(precomputed_crc32, size_of_the_blob_computed_from)
153
153
  ```
154
154
 
155
+ You can also compute the CRC32 for an entire IO object if it responds to `#eof?`:
156
+
157
+ ```ruby
158
+ crc = ZipTricks::StreamCRC32.from_io(file) # Returns an Integer
159
+ ```
160
+
155
161
  ## Reading ZIP files
156
162
 
157
163
  The library contains a reader module, play with it to see what is possible. It is not a complete ZIP reader
@@ -160,7 +166,7 @@ as such it performs it's function quite well. Please beware of the security impl
160
166
  that have not been formally verified (ours hasn't been).
161
167
 
162
168
  ## Contributing to zip_tricks
163
-
169
+
164
170
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
165
171
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
166
172
  * Fork the project.
@@ -172,4 +178,4 @@ that have not been formally verified (ours hasn't been).
172
178
 
173
179
  ## Copyright
174
180
 
175
- Copyright (c) 2016 WeTransfer. See LICENSE.txt for further details.
181
+ Copyright (c) 2019 WeTransfer. See LICENSE.txt for further details.
@@ -2,13 +2,26 @@
2
2
 
3
3
  # A simple stateful class for keeping track of a CRC32 value through multiple writes
4
4
  class ZipTricks::StreamCRC32
5
+ STRINGS_HAVE_CAPACITY_SUPPORT = begin
6
+ String.new('', capacity: 1)
7
+ true
8
+ rescue ArgumentError
9
+ false
10
+ end
11
+ CRC_BUF_SIZE = 1024 * 512
12
+ private_constant :STRINGS_HAVE_CAPACITY_SUPPORT, :CRC_BUF_SIZE
13
+
5
14
  # Compute a CRC32 value from an IO object. The object should respond to `read` and `eof?`
6
15
  #
7
16
  # @param io[IO] the IO to read the data from
8
17
  # @return [Fixnum] the computed CRC32 value
9
18
  def self.from_io(io)
19
+ # If we can specify the string capacity upfront we will not have to resize
20
+ # the string during operation. This saves time but is only available on
21
+ # recent Ruby 2.x versions.
22
+ blob = STRINGS_HAVE_CAPACITY_SUPPORT ? String.new('', capacity: CRC_BUF_SIZE) : String.new('')
10
23
  crc = new
11
- crc << io.read(1024 * 512) until io.eof?
24
+ crc << io.read(CRC_BUF_SIZE, blob) until io.eof?
12
25
  crc.to_i
13
26
  end
14
27
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZipTricks
4
- VERSION = '4.7.3'
4
+ VERSION = '4.7.4'
5
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Some operations (such as CRC32) benefit when they are performed
2
4
  # on larger chunks of data. In certain use cases, it is possible that
3
5
  # the consumer of ZipTricks is going to be writing small chunks
data/zip_tricks.gemspec CHANGED
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency 'complexity_assert'
41
41
  spec.add_development_dependency 'coderay'
42
42
  spec.add_development_dependency 'benchmark-ips'
43
+ spec.add_development_dependency 'allocation_stats', '~> 0.1.5'
43
44
  spec.add_development_dependency 'yard', '~> 0.9'
44
45
  spec.add_development_dependency 'wetransfer_style', '0.6.0'
45
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zip_tricks
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.3
4
+ version: 4.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-06 00:00:00.000000000 Z
11
+ date: 2019-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: allocation_stats
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.1.5
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.1.5
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: yard
155
169
  requirement: !ruby/object:Gem::Requirement