zip_tricks 4.5.0 → 4.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd1865613940a7038642206baf6cd58457b87ff5
4
- data.tar.gz: 3ebda3c665c9671d9f033d6f768ccdc800d7f2f9
3
+ metadata.gz: e248ba8b5366308587a9a56968b14d3f9625b905
4
+ data.tar.gz: 7038b66a1cf64ee3dc745be2c9d558825aa8673b
5
5
  SHA512:
6
- metadata.gz: c16f15ab10788d90fe96e61e8ecf20a20eee6a7e94d2d22538c34964d51eb9ee4cc64459dd46997f2b994212944e34e8162d7880ff4d79343c86a5d1ed09fd77
7
- data.tar.gz: da1d6e24031365ea67fc2fa0fbf3096f57b007c6ac35449b57b1783eecfa703d530c1c695429335bee252a841da6722f3bca341bd6fc8c5e9e24bf6379edee76
6
+ metadata.gz: 5c849e7ba92b7f7d7b6af57447c703f970b71a00ba25bcd0fc7ff632ef93d61169cbbafc505e82b0d0a3e96631db0b2e400b23dc31e1dda161456db1eda8d9d6
7
+ data.tar.gz: 22f7c757eb8117ae48292158a657f8b288efd9b56b7c85a94323590fd3f607d033a2a3e7d61849b786435ccd8f34ee7971ee66f2c9d951f44128343de773b5e1
data/.rubocop.yml CHANGED
@@ -77,3 +77,6 @@ Layout/SpaceInsideHashLiteralBraces:
77
77
 
78
78
  Style/Alias:
79
79
  EnforcedStyle: prefer_alias_method
80
+
81
+ Style/ZeroLengthPredicate:
82
+ Enabled: false # Does not work for StringIOs
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 4.5.1
2
+
3
+ * Speed up CRC32 calculation using a buffer of 5MB (have to combine CRCs less often)
4
+
1
5
  ## 4.5.0
2
6
 
3
7
  * Rename `Streamer#add_compressed_entry` and `SizeEstimator#add_compressed_entry` to `add_deflated_entry`
@@ -2,18 +2,21 @@
2
2
 
3
3
  # A simple stateful class for keeping track of a CRC32 value through multiple writes
4
4
  class ZipTricks::StreamCRC32
5
+ BUFFER_SIZE = 1024 * 1024 * 5
6
+
5
7
  # Compute a CRC32 value from an IO object. The object should respond to `read` and `eof?`
6
8
  #
7
9
  # @param io[IO] the IO to read the data from
8
10
  # @return [Fixnum] the computed CRC32 value
9
11
  def self.from_io(io)
10
12
  crc = new
11
- crc << io.read(1024 * 512) until io.eof?
13
+ crc << io.read(BUFFER_SIZE) until io.eof?
12
14
  crc.to_i
13
15
  end
14
16
 
15
17
  # Creates a new streaming CRC32 calculator
16
18
  def initialize
19
+ @buf = StringIO.new
17
20
  @crc = Zlib.crc32('')
18
21
  end
19
22
 
@@ -22,7 +25,8 @@ class ZipTricks::StreamCRC32
22
25
  # @param blob[String] the string to compute the CRC32 from
23
26
  # @return [self]
24
27
  def <<(blob)
25
- @crc = Zlib.crc32_combine(@crc, Zlib.crc32(blob), blob.bytesize)
28
+ @buf << blob
29
+ buf_flush if @buf.size > BUFFER_SIZE
26
30
  self
27
31
  end
28
32
 
@@ -30,6 +34,7 @@ class ZipTricks::StreamCRC32
30
34
  #
31
35
  # @return [Fixnum] the updated CRC32 value for all the blobs so far
32
36
  def to_i
37
+ buf_flush if @buf.size > 0
33
38
  @crc
34
39
  end
35
40
 
@@ -40,6 +45,15 @@ class ZipTricks::StreamCRC32
40
45
  # @param blob_size[Fixnum] the size of the daata the `crc32` is computed from
41
46
  # @return [Fixnum] the updated CRC32 value for all the blobs so far
42
47
  def append(crc32, blob_size)
48
+ buf_flush if @buf.size > 0
43
49
  @crc = Zlib.crc32_combine(@crc, crc32, blob_size)
44
50
  end
51
+
52
+ private
53
+
54
+ def buf_flush
55
+ @crc = Zlib.crc32_combine(@crc, Zlib.crc32(@buf.string), @buf.size)
56
+ @buf.truncate(0)
57
+ @buf.rewind
58
+ end
45
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZipTricks
4
- VERSION = '4.5.0'
4
+ VERSION = '4.5.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zip_tricks
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.0
4
+ version: 4.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov