zip_tricks 2.6.0 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ describe ZipTricks::Streamer do
6
6
  let(:test_text_file_path) {
7
7
  File.join(__dir__, 'war-and-peace.txt')
8
8
  }
9
-
9
+
10
10
  # Run each test in a temporady directory, and nuke it afterwards
11
11
  around(:each) do |example|
12
12
  wd = Dir.pwd
@@ -16,68 +16,68 @@ describe ZipTricks::Streamer do
16
16
  end
17
17
  Dir.chdir(wd)
18
18
  end
19
-
19
+
20
20
  def rewind_after(*ios)
21
21
  yield.tap { ios.map(&:rewind) }
22
22
  end
23
-
23
+
24
24
  it 'raises an InvalidOutput if the given object does not support the methods' do
25
25
  expect {
26
26
  described_class.new(nil)
27
27
  }.to raise_error(ZipTricks::Streamer::InvalidOutput)
28
28
  end
29
-
29
+
30
30
  it 'returns the position in the IO at every call' do
31
31
  io = StringIO.new
32
32
  zip = described_class.new(io)
33
33
  pos = zip.add_compressed_entry('file.jpg', 182919, 8921, 8912)
34
34
  expect(pos).to eq(io.tell)
35
35
  expect(pos).to eq(38)
36
-
36
+
37
37
  retval = zip << SecureRandom.random_bytes(8912)
38
38
  expect(retval).to eq(zip)
39
39
  expect(io.tell).to eq(8950)
40
-
40
+
41
41
  pos = zip.add_stored_entry('file.jpg', 8921, 182919)
42
42
  expect(pos).to eq(8988)
43
43
  zip << SecureRandom.random_bytes(8921)
44
44
  expect(io.tell).to eq(17909)
45
-
45
+
46
46
  pos = zip.write_central_directory!
47
47
  expect(pos).to eq(io.tell)
48
48
  expect(pos).to eq(17985)
49
-
49
+
50
50
  pos_after_close = zip.close
51
51
  expect(pos_after_close).to eq(pos)
52
52
  end
53
-
53
+
54
54
  it 'can write and then read the block-deflated files' do
55
55
  f = Tempfile.new('raw')
56
56
  f.binmode
57
-
57
+
58
58
  rewind_after(f) do
59
59
  f << ('A' * 1024 * 1024)
60
60
  f << SecureRandom.random_bytes(1248)
61
61
  f << ('B' * 1024 * 1024)
62
62
  end
63
-
63
+
64
64
  crc = rewind_after(f) { Zlib.crc32(f.read) }
65
-
65
+
66
66
  compressed_blockwise = StringIO.new
67
67
  rewind_after(compressed_blockwise, f) do
68
68
  ZipTricks::BlockDeflate.deflate_in_blocks_and_terminate(f, compressed_blockwise, block_size: 1024)
69
69
  end
70
-
70
+
71
71
  # Perform the zipping
72
72
  zip_file = Tempfile.new('z')
73
73
  zip_file.binmode
74
-
74
+
75
75
  described_class.open(zip_file) do |zip|
76
76
  zip.add_compressed_entry("compressed-file.bin", f.size, crc, compressed_blockwise.size)
77
77
  zip << compressed_blockwise.read
78
78
  end
79
79
  zip_file.flush
80
-
80
+
81
81
  per_filename = {}
82
82
  Zip::File.open(zip_file.path) do |zip_file|
83
83
  # Handle entries one by one
@@ -86,82 +86,82 @@ describe ZipTricks::Streamer do
86
86
  per_filename[entry.name] = entry.get_input_stream.read
87
87
  end
88
88
  end
89
-
89
+
90
90
  expect(per_filename['compressed-file.bin'].bytesize).to eq(f.size)
91
91
  expect(Digest::SHA1.hexdigest(per_filename['compressed-file.bin'])).to eq(Digest::SHA1.hexdigest(f.read))
92
-
92
+
93
93
  output = `unzip -v #{zip_file.path}`
94
94
  puts output.inspect
95
95
  end
96
96
 
97
-
97
+
98
98
  it 'creates an archive that OSX ArchiveUtility can handle' do
99
99
  au_path = '/System/Library/CoreServices/Applications/Archive Utility.app/Contents/MacOS/Archive Utility'
100
100
  unless File.exist?(au_path)
101
101
  skip "This system does not have ArchiveUtility"
102
102
  end
103
-
103
+
104
104
  outbuf = Tempfile.new('zip')
105
105
  outbuf.binmode
106
-
106
+
107
107
  zip = ZipTricks::Streamer.new(outbuf)
108
-
108
+
109
109
  File.open(test_text_file_path, 'rb') do | source_f |
110
110
  crc32 = rewind_after(source_f) { Zlib.crc32(source_f.read) }
111
-
111
+
112
112
  compressed_buffer = StringIO.new
113
-
113
+
114
114
  expect(ZipTricks::BlockDeflate).to receive(:deflate_chunk).at_least(:twice).and_call_original
115
-
115
+
116
116
  # Compress in blocks of 4 Kb
117
117
  rewind_after(source_f, compressed_buffer) do
118
118
  ZipTricks::BlockDeflate.deflate_in_blocks_and_terminate(source_f, compressed_buffer, block_size: 1024 * 4)
119
119
  end
120
-
120
+
121
121
  # Add this file compressed...
122
122
  zip.add_compressed_entry('war-and-peace.txt', source_f.size, crc32, compressed_buffer.size)
123
123
  zip << compressed_buffer.string
124
-
124
+
125
125
  # ...and stored.
126
126
  zip.add_stored_entry('war-and-peace-raw.txt', source_f.size, crc32)
127
127
  zip << source_f.read
128
-
128
+
129
129
  zip.close
130
-
130
+
131
131
  outbuf.flush
132
132
  File.unlink('test.zip') rescue nil
133
133
  File.rename(outbuf.path, 'osx-archive-test.zip')
134
-
134
+
135
135
  # ArchiveUtility sometimes puts the stuff it unarchives in ~/Downloads etc. so do
136
136
  # not perform any checks on the files since we do not really know where they are on disk.
137
137
  # Visual inspection should show whether the unarchiving is handled correctly.
138
138
  `#{Shellwords.join([au_path, 'osx-archive-test.zip'])}`
139
139
  end
140
-
140
+
141
141
  FileUtils.rm_rf('osx-archive-test')
142
142
  FileUtils.rm_rf('osx-archive-test.zip')
143
143
  end
144
-
144
+
145
145
  it 'archives files which can then be read using the usual means with Rubyzip' do
146
146
  zip_buf = Tempfile.new('zipp')
147
147
  zip_buf.binmode
148
148
  output_io = double('IO')
149
-
149
+
150
150
  # Only allow the methods we provide in BlockWrite.
151
151
  # Will raise an error if other methods are triggered (the ones that
152
152
  # might try to rewind the IO).
153
153
  allow(output_io).to receive(:<<) {|data|
154
154
  zip_buf << data.to_s.force_encoding(Encoding::BINARY)
155
155
  }
156
-
156
+
157
157
  allow(output_io).to receive(:tell) { zip_buf.tell }
158
158
  allow(output_io).to receive(:pos) { zip_buf.pos }
159
159
  allow(output_io).to receive(:close)
160
-
160
+
161
161
  # Generate a couple of random files
162
162
  raw_file_1 = SecureRandom.random_bytes(1024 * 20)
163
163
  raw_file_2 = SecureRandom.random_bytes(1024 * 128)
164
-
164
+
165
165
  # Perform the zipping
166
166
  zip = described_class.new(output_io)
167
167
  zip.add_stored_entry("first-file.bin", raw_file_1.size, Zlib.crc32(raw_file_1))
@@ -169,9 +169,9 @@ describe ZipTricks::Streamer do
169
169
  zip.add_stored_entry("second-file.bin", raw_file_2.size, Zlib.crc32(raw_file_2))
170
170
  zip << raw_file_2
171
171
  zip.close
172
-
172
+
173
173
  zip_buf.flush
174
-
174
+
175
175
  per_filename = {}
176
176
  Zip::File.open(zip_buf.path) do |zip_file|
177
177
  # Handle entries one by one
@@ -181,10 +181,10 @@ describe ZipTricks::Streamer do
181
181
  per_filename[entry.name] = entry.get_input_stream.read
182
182
  end
183
183
  end
184
-
184
+
185
185
  expect(per_filename['first-file.bin'].unpack("C*")).to eq(raw_file_1.unpack("C*"))
186
186
  expect(per_filename['second-file.bin'].unpack("C*")).to eq(raw_file_2.unpack("C*"))
187
-
187
+
188
188
  wd = Dir.pwd
189
189
  Dir.mktmpdir do | td |
190
190
  Dir.chdir(td)
@@ -193,15 +193,15 @@ describe ZipTricks::Streamer do
193
193
  end
194
194
  Dir.chdir(wd)
195
195
  end
196
-
196
+
197
197
  it 'sets the general-purpose flag for entries with UTF8 names' do
198
198
  zip_buf = Tempfile.new('zipp')
199
199
  zip_buf.binmode
200
-
200
+
201
201
  # Generate a couple of random files
202
202
  raw_file_1 = SecureRandom.random_bytes(1024 * 20)
203
203
  raw_file_2 = SecureRandom.random_bytes(1024 * 128)
204
-
204
+
205
205
  # Perform the zipping
206
206
  zip = described_class.new(zip_buf)
207
207
  zip.add_stored_entry("first-file.bin", raw_file_1.size, Zlib.crc32(raw_file_1))
@@ -209,24 +209,24 @@ describe ZipTricks::Streamer do
209
209
  zip.add_stored_entry("второй-файл.bin", raw_file_2.size, Zlib.crc32(raw_file_2))
210
210
  zip << raw_file_2
211
211
  zip.close
212
-
212
+
213
213
  zip_buf.flush
214
-
214
+
215
215
  entries = []
216
216
  Zip::File.open(zip_buf.path) do |zip_file|
217
217
  # Handle entries one by one
218
218
  zip_file.each {|entry| entries << entry }
219
219
  first_entry, second_entry = entries
220
-
220
+
221
221
  expect(first_entry.gp_flags).to eq(0)
222
222
  expect(first_entry.name).to eq('first-file.bin')
223
-
223
+
224
224
  # Rubyzip does not properly set the encoding of the entries it reads
225
225
  expect(second_entry.gp_flags).to eq(2048)
226
226
  expect(second_entry.name).to eq("второй-файл.bin".force_encoding(Encoding::BINARY))
227
227
  end
228
228
  end
229
-
229
+
230
230
  it 'raises when the actual bytes written for a stored entry does not match the entry header' do
231
231
  expect {
232
232
  ZipTricks::Streamer.open(StringIO.new) do | zip |
@@ -4,13 +4,13 @@ describe ZipTricks::WriteAndTell do
4
4
  it 'maintains the count of bytes written' do
5
5
  adapter = described_class.new('')
6
6
  expect(adapter.tell).to be_zero
7
-
7
+
8
8
  adapter << 'hello'
9
9
  adapter << ''
10
10
  adapter << '!'
11
11
  expect(adapter.tell).to eq(6)
12
12
  end
13
-
13
+
14
14
  it 'is able to write frozen String objects in different encodings, converting them to binary' do
15
15
  strs = [
16
16
  [12, 123, 0, 3].pack("C*"),
@@ -18,20 +18,20 @@ describe ZipTricks::WriteAndTell do
18
18
  "текста замороженный кусок".freeze,
19
19
  [12, 123, 0, 3].pack("C*"),
20
20
  ]
21
-
21
+
22
22
  buf = 'превед'.force_encoding(Encoding::BINARY)
23
23
  writer = described_class.new(buf)
24
24
  strs.each {|s| writer << s }
25
25
  expect(writer.tell).to eq(79)
26
26
  expect(buf.bytesize).to eq(91) # It already contained some bytes
27
27
  end
28
-
28
+
29
29
  it 'advances the internal pointer using advance_position_by' do
30
30
  str = ''
31
-
31
+
32
32
  adapter = described_class.new(str)
33
33
  expect(adapter.tell).to be_zero
34
-
34
+
35
35
  adapter << 'hello'
36
36
  adapter << ''
37
37
  adapter << '!'
data/zip_tricks.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: zip_tricks 2.6.0 ruby lib
5
+ # stub: zip_tricks 2.6.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "zip_tricks"
9
- s.version = "2.6.0"
9
+ s.version = "2.6.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Julik Tarkhanov"]
14
- s.date = "2016-07-01"
14
+ s.date = "2016-07-14"
15
15
  s.description = "Makes rubyzip stream, for real"
16
16
  s.email = "me@julik.nl"
17
17
  s.extra_rdoc_files = [
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: 2.6.0
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-01 00:00:00.000000000 Z
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip