zip_tricks 4.5.0 → 4.5.1
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 +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/lib/zip_tricks/stream_crc32.rb +16 -2
- data/lib/zip_tricks/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e248ba8b5366308587a9a56968b14d3f9625b905
|
4
|
+
data.tar.gz: 7038b66a1cf64ee3dc745be2c9d558825aa8673b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c849e7ba92b7f7d7b6af57447c703f970b71a00ba25bcd0fc7ff632ef93d61169cbbafc505e82b0d0a3e96631db0b2e400b23dc31e1dda161456db1eda8d9d6
|
7
|
+
data.tar.gz: 22f7c757eb8117ae48292158a657f8b288efd9b56b7c85a94323590fd3f607d033a2a3e7d61849b786435ccd8f34ee7971ee66f2c9d951f44128343de773b5e1
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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(
|
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
|
-
@
|
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
|
data/lib/zip_tricks/version.rb
CHANGED