pr-zlib 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +1 -0
- data/CHANGES +23 -13
- data/MANIFEST +20 -18
- data/README +52 -42
- data/Rakefile +116 -119
- data/bin/minizip.rb +173 -173
- data/certs/djberg96_pub.pem +21 -0
- data/examples/example_rbzlib.rb +385 -385
- data/lib/pr-zlib.rb +1 -0
- data/lib/pr/rbzlib.rb +5079 -5060
- data/lib/pr/zlib.rb +1567 -1554
- data/pr-zlib.gemspec +24 -22
- data/profile/bench_pr_zlib.rb +43 -43
- data/profile/bench_zlib.rb +43 -43
- data/profile/profile_pr_zlib_read.rb +28 -28
- data/profile/profile_pr_zlib_write.rb +26 -26
- data/test/test_zlib.rb +168 -160
- data/test/test_zlib_gzip_reader.rb +183 -183
- data/test/test_zlib_gzip_writer.rb +186 -184
- data/test/test_zlib_zstream.rb +146 -146
- metadata +41 -9
- metadata.gz.sig +0 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkamJl
|
3
|
+
cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
4
|
+
MB4XDTE1MDkwMjIwNDkxOFoXDTE2MDkwMTIwNDkxOFowPzERMA8GA1UEAwwIZGpi
|
5
|
+
ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
6
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyTkvXqRp6hLs9eoJOS
|
7
|
+
Hmi8kRYbq9Vkf15/hMxJpotYMgJVHHWrmDcC5Dye2PbnXjTkKf266Zw0PtT9h+lI
|
8
|
+
S3ts9HO+vaCFSMwFFZmnWJSpQ3CNw2RcHxjWkk9yF7imEM8Kz9ojhiDXzBetdV6M
|
9
|
+
gr0lV/alUr7TNVBDngbXEfTWscyXh1qd7xZ4EcOdsDktCe5G45N/o3662tPQvJsi
|
10
|
+
FOF0CM/KuBsa/HL1/eoEmF4B3EKIRfTHrQ3hu20Kv3RJ88QM4ec2+0dd97uX693O
|
11
|
+
zv6981fyEg+aXLkxrkViM/tz2qR2ZE0jPhHTREPYeMEgptRkTmWSKAuLVWrJEfgl
|
12
|
+
DtkCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFEwe
|
13
|
+
nn6bfJADmuIDiMSOzedOrL+xMB0GA1UdEQQWMBSBEmRqYmVyZzk2QGdtYWlsLmNv
|
14
|
+
bTAdBgNVHRIEFjAUgRJkamJlcmc5NkBnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD
|
15
|
+
ggEBAHmNOCWoDVD75zHFueY0viwGDVP1BNGFC+yXcb7u2GlK+nEMCORqzURbYPf7
|
16
|
+
tL+/hzmePIRz7i30UM//64GI1NLv9jl7nIwjhPpXpf7/lu2I9hOTsvwSumb5UiKC
|
17
|
+
/sqBxI3sfj9pr79Wpv4MuikX1XPik7Ncb7NPsJPw06Lvyc3Hkg5X2XpPtLtS+Gr2
|
18
|
+
wKJnmzb5rIPS1cmsqv0M9LPWflzfwoZ/SpnmhagP+g05p8bRNKjZSA2iImM/GyYZ
|
19
|
+
EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
|
20
|
+
tGSHgAmcLlkdGgan182qsE/4kKM=
|
21
|
+
-----END CERTIFICATE-----
|
data/examples/example_rbzlib.rb
CHANGED
@@ -1,385 +1,385 @@
|
|
1
|
-
# example.rb -- usage example of the zlib compression library
|
2
|
-
# Copyright (C) 1995-2004 Jean-loup Gailly.
|
3
|
-
# For conditions of distribution and use, see copyright notice in rbzlib.rb
|
4
|
-
#
|
5
|
-
# Ruby translation by Park Heesob
|
6
|
-
|
7
|
-
require 'rbzlib'
|
8
|
-
include Rbzlib
|
9
|
-
|
10
|
-
def CHECK_ERR(err,msg)
|
11
|
-
if(err != Z_OK)
|
12
|
-
raise RuntimeError,"#{msg} error: #{err}"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
TESTFILE = "foo.gz"
|
17
|
-
@@hello = "hello, hello!\0"
|
18
|
-
|
19
|
-
@@dictionary = "hello"
|
20
|
-
|
21
|
-
def test_compress(compr, comprLen, uncompr, uncomprLen)
|
22
|
-
len = @@hello.length
|
23
|
-
|
24
|
-
err,comprLen = compress(compr, comprLen, @@hello, len)
|
25
|
-
CHECK_ERR(err, "compress")
|
26
|
-
compr = compr[0,comprLen]
|
27
|
-
uncompr[0,7] = "garbage"
|
28
|
-
err,uncomprLen = uncompress(uncompr, uncomprLen, compr, comprLen)
|
29
|
-
CHECK_ERR(err, "uncompress")
|
30
|
-
uncompr = uncompr[0,uncomprLen]
|
31
|
-
if uncompr != @@hello
|
32
|
-
puts("bad uncompress")
|
33
|
-
exit(1)
|
34
|
-
else
|
35
|
-
puts("uncompress(): #{uncompr}")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_gzio(fname, uncompr, uncomprLen)
|
40
|
-
len = @@hello.length
|
41
|
-
err = 0
|
42
|
-
file = gzopen(fname, "wb")
|
43
|
-
if file.nil?
|
44
|
-
puts("gzopen error")
|
45
|
-
exit(1)
|
46
|
-
end
|
47
|
-
gzputc(file, 'h')
|
48
|
-
if (gzputs(file, "ello") != 4)
|
49
|
-
puts("gzputs err: #{gzerror(file, err)}")
|
50
|
-
exit(1)
|
51
|
-
end
|
52
|
-
if (gzputs(file, ", hello!") != 8)
|
53
|
-
puts("gzputs err: #{gzerror(file, err)}")
|
54
|
-
exit(1)
|
55
|
-
end
|
56
|
-
gzseek(file, 1, SEEK_CUR)
|
57
|
-
gzclose(file)
|
58
|
-
|
59
|
-
file = gzopen(fname, "rb")
|
60
|
-
if file.nil?
|
61
|
-
puts("gzopen error")
|
62
|
-
exit(1)
|
63
|
-
end
|
64
|
-
uncompr[0,7] = "garbage"
|
65
|
-
if (gzread(file, uncompr, uncomprLen) != len)
|
66
|
-
puts("gzread err: #{gzerror(file, err)}")
|
67
|
-
exit(1)
|
68
|
-
end
|
69
|
-
uncompr = uncompr[0,len]
|
70
|
-
if uncompr != @@hello
|
71
|
-
puts("bad gzread: #{uncompr}")
|
72
|
-
exit(1)
|
73
|
-
else
|
74
|
-
puts("gzread(): #{uncompr}")
|
75
|
-
end
|
76
|
-
pos = gzseek(file, -8, SEEK_CUR)
|
77
|
-
if (pos != 6 || gztell(file) != pos)
|
78
|
-
puts("gzseek error, pos=#{pos}, gztell=#{gztell(file)}")
|
79
|
-
exit(1)
|
80
|
-
end
|
81
|
-
|
82
|
-
if (gzgetc(file) != ' ')
|
83
|
-
puts("gzgetc error")
|
84
|
-
exit(1)
|
85
|
-
end
|
86
|
-
|
87
|
-
if (gzungetc(' ', file) != ' ')
|
88
|
-
puts("gzungetc error")
|
89
|
-
exit(1)
|
90
|
-
end
|
91
|
-
|
92
|
-
gzgets(file, uncompr, uncomprLen)
|
93
|
-
uncompr.chop!
|
94
|
-
if uncompr.length != 7
|
95
|
-
puts("gzgets err after gzseek: #{gzerror(file, err)}")
|
96
|
-
exit(1)
|
97
|
-
end
|
98
|
-
|
99
|
-
if uncompr != @@hello[6..-2]
|
100
|
-
puts("bad gzgets after gzseek")
|
101
|
-
exit(1)
|
102
|
-
else
|
103
|
-
puts("gzgets() after gzseek: #{uncompr}")
|
104
|
-
end
|
105
|
-
|
106
|
-
gzclose(file)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_deflate(compr, comprLen)
|
110
|
-
c_stream = Z_stream.new
|
111
|
-
len = @@hello.length
|
112
|
-
|
113
|
-
err = deflateInit(c_stream, Z_DEFAULT_COMPRESSION)
|
114
|
-
CHECK_ERR(err, "deflateInit")
|
115
|
-
|
116
|
-
c_stream.next_in = Bytef.new(@@hello)
|
117
|
-
c_stream.next_out = Bytef.new(compr)
|
118
|
-
|
119
|
-
while (c_stream.total_in != len && c_stream.total_out < comprLen)
|
120
|
-
c_stream.avail_in = c_stream.avail_out = 1
|
121
|
-
err = deflate(c_stream, Z_NO_FLUSH)
|
122
|
-
CHECK_ERR(err, "deflate")
|
123
|
-
end
|
124
|
-
while true
|
125
|
-
c_stream.avail_out = 1
|
126
|
-
err = deflate(c_stream, Z_FINISH)
|
127
|
-
break if (err == Z_STREAM_END)
|
128
|
-
CHECK_ERR(err, "deflate")
|
129
|
-
end
|
130
|
-
|
131
|
-
err = deflateEnd(c_stream)
|
132
|
-
CHECK_ERR(err, "deflateEnd")
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_inflate(compr, comprLen, uncompr, uncomprLen)
|
136
|
-
uncompr[0,7] = "garbage"
|
137
|
-
d_stream = Z_stream.new
|
138
|
-
|
139
|
-
d_stream.next_in = Bytef.new(compr)
|
140
|
-
d_stream.avail_in = 0
|
141
|
-
d_stream.next_out = Bytef.new(uncompr)
|
142
|
-
|
143
|
-
err = inflateInit(d_stream)
|
144
|
-
CHECK_ERR(err, "inflateInit")
|
145
|
-
|
146
|
-
while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
|
147
|
-
d_stream.avail_in = d_stream.avail_out = 1
|
148
|
-
err = inflate(d_stream, Z_NO_FLUSH)
|
149
|
-
break if (err == Z_STREAM_END)
|
150
|
-
CHECK_ERR(err, "inflate")
|
151
|
-
end
|
152
|
-
|
153
|
-
err = inflateEnd(d_stream)
|
154
|
-
CHECK_ERR(err, "inflateEnd")
|
155
|
-
uncompr = uncompr[0,d_stream.total_out]
|
156
|
-
if uncompr != @@hello
|
157
|
-
puts("bad inflate")
|
158
|
-
exit(1)
|
159
|
-
else
|
160
|
-
puts("inflate(): #{uncompr}")
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
165
|
-
c_stream = Z_stream.new
|
166
|
-
err = deflateInit(c_stream, Z_BEST_SPEED)
|
167
|
-
CHECK_ERR(err, "deflateInit")
|
168
|
-
|
169
|
-
c_stream.next_out = Bytef.new(compr)
|
170
|
-
c_stream.avail_out = comprLen
|
171
|
-
c_stream.next_in = Bytef.new(uncompr)
|
172
|
-
c_stream.avail_in = uncomprLen
|
173
|
-
err = deflate(c_stream, Z_NO_FLUSH)
|
174
|
-
CHECK_ERR(err, "deflate")
|
175
|
-
if c_stream.avail_in.nonzero?
|
176
|
-
puts("deflate not greedy")
|
177
|
-
exit(1)
|
178
|
-
end
|
179
|
-
|
180
|
-
deflateParams(c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY)
|
181
|
-
c_stream.next_in = Bytef.new(compr)
|
182
|
-
c_stream.avail_in = comprLen/2
|
183
|
-
err = deflate(c_stream, Z_NO_FLUSH)
|
184
|
-
CHECK_ERR(err, "deflate")
|
185
|
-
|
186
|
-
deflateParams(c_stream, Z_BEST_COMPRESSION, Z_FILTERED)
|
187
|
-
c_stream.next_in = Bytef.new(uncompr)
|
188
|
-
c_stream.avail_in = uncomprLen
|
189
|
-
err = deflate(c_stream, Z_NO_FLUSH)
|
190
|
-
CHECK_ERR(err, "deflate")
|
191
|
-
|
192
|
-
err = deflate(c_stream, Z_FINISH)
|
193
|
-
if (err != Z_STREAM_END)
|
194
|
-
puts("deflate should report Z_STREAM_END")
|
195
|
-
exit(1)
|
196
|
-
end
|
197
|
-
err = deflateEnd(c_stream)
|
198
|
-
CHECK_ERR(err, "deflateEnd")
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
202
|
-
d_stream = Z_stream.new
|
203
|
-
uncompr[0,7] = "garbage"
|
204
|
-
|
205
|
-
d_stream.next_in = Bytef.new(compr)
|
206
|
-
d_stream.avail_in = comprLen
|
207
|
-
|
208
|
-
err = inflateInit(d_stream)
|
209
|
-
CHECK_ERR(err, "inflateInit")
|
210
|
-
|
211
|
-
while true
|
212
|
-
d_stream.next_out = Bytef.new(uncompr)
|
213
|
-
d_stream.avail_out = uncomprLen
|
214
|
-
err = inflate(d_stream, Z_NO_FLUSH)
|
215
|
-
break if (err == Z_STREAM_END)
|
216
|
-
CHECK_ERR(err, "large inflate")
|
217
|
-
end
|
218
|
-
|
219
|
-
err = inflateEnd(d_stream)
|
220
|
-
CHECK_ERR(err, "inflateEnd")
|
221
|
-
|
222
|
-
if (d_stream.total_out != 2*uncomprLen + comprLen/2)
|
223
|
-
puts("bad large inflate: #{d_stream.total_out}")
|
224
|
-
exit(1)
|
225
|
-
else
|
226
|
-
puts("large_inflate(): OK")
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_flush(compr, comprLen)
|
231
|
-
c_stream = Z_stream.new
|
232
|
-
len = @@hello.length
|
233
|
-
|
234
|
-
err = deflateInit(c_stream, Z_DEFAULT_COMPRESSION)
|
235
|
-
CHECK_ERR(err, "deflateInit")
|
236
|
-
|
237
|
-
c_stream.next_in = Bytef.new(@@hello)
|
238
|
-
c_stream.next_out = Bytef.new(compr)
|
239
|
-
c_stream.avail_in = 3
|
240
|
-
c_stream.avail_out = comprLen
|
241
|
-
err = deflate(c_stream, Z_FULL_FLUSH)
|
242
|
-
CHECK_ERR(err, "deflate")
|
243
|
-
|
244
|
-
compr[3]=(compr[3].ord+1).chr
|
245
|
-
c_stream.avail_in = len - 3
|
246
|
-
|
247
|
-
err = deflate(c_stream, Z_FINISH)
|
248
|
-
if (err != Z_STREAM_END)
|
249
|
-
CHECK_ERR(err, "deflate")
|
250
|
-
end
|
251
|
-
err = deflateEnd(c_stream)
|
252
|
-
CHECK_ERR(err, "deflateEnd")
|
253
|
-
|
254
|
-
comprLen = c_stream.total_out
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_sync(compr, comprLen, uncompr, uncomprLen)
|
258
|
-
d_stream = Z_stream.new
|
259
|
-
uncompr[0,7] = "garbage"
|
260
|
-
|
261
|
-
d_stream.next_in = Bytef.new(compr)
|
262
|
-
d_stream.avail_in = 2
|
263
|
-
|
264
|
-
err = inflateInit(d_stream)
|
265
|
-
CHECK_ERR(err, "inflateInit")
|
266
|
-
|
267
|
-
d_stream.next_out = Bytef.new(uncompr)
|
268
|
-
d_stream.avail_out = uncomprLen
|
269
|
-
|
270
|
-
inflate(d_stream, Z_NO_FLUSH)
|
271
|
-
CHECK_ERR(err, "inflate")
|
272
|
-
|
273
|
-
d_stream.avail_in = comprLen-2
|
274
|
-
err = inflateSync(d_stream)
|
275
|
-
CHECK_ERR(err, "inflateSync")
|
276
|
-
|
277
|
-
err = inflate(d_stream, Z_FINISH)
|
278
|
-
if (err != Z_DATA_ERROR)
|
279
|
-
puts("inflate should report DATA_ERROR")
|
280
|
-
exit(1)
|
281
|
-
end
|
282
|
-
err = inflateEnd(d_stream)
|
283
|
-
uncompr = uncompr[0,d_stream.total_out]
|
284
|
-
CHECK_ERR(err, "inflateEnd")
|
285
|
-
puts("after inflateSync(): hel#{uncompr}")
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_dict_deflate(compr, comprLen)
|
289
|
-
c_stream = Z_stream.new
|
290
|
-
err = deflateInit(c_stream, Z_BEST_COMPRESSION)
|
291
|
-
CHECK_ERR(err, "deflateInit")
|
292
|
-
|
293
|
-
err = deflateSetDictionary(c_stream,@@dictionary, @@dictionary.length)
|
294
|
-
CHECK_ERR(err, "deflateSetDictionary")
|
295
|
-
|
296
|
-
@@dictId = c_stream.adler
|
297
|
-
c_stream.next_out = Bytef.new(compr)
|
298
|
-
c_stream.avail_out = comprLen
|
299
|
-
|
300
|
-
c_stream.next_in = Bytef.new(@@hello)
|
301
|
-
c_stream.avail_in = @@hello.length
|
302
|
-
|
303
|
-
err = deflate(c_stream, Z_FINISH)
|
304
|
-
if (err != Z_STREAM_END)
|
305
|
-
puts("deflate should report Z_STREAM_END")
|
306
|
-
exit(1)
|
307
|
-
end
|
308
|
-
err = deflateEnd(c_stream)
|
309
|
-
CHECK_ERR(err, "deflateEnd")
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
313
|
-
d_stream = Z_stream.new
|
314
|
-
uncompr[0,7] = "garbage"
|
315
|
-
|
316
|
-
d_stream.next_in = Bytef.new(compr)
|
317
|
-
d_stream.avail_in = comprLen
|
318
|
-
|
319
|
-
err = inflateInit(d_stream)
|
320
|
-
CHECK_ERR(err, "inflateInit")
|
321
|
-
d_stream.next_out = Bytef.new(uncompr)
|
322
|
-
d_stream.avail_out = uncomprLen
|
323
|
-
|
324
|
-
while true
|
325
|
-
err = inflate(d_stream, Z_NO_FLUSH)
|
326
|
-
break if (err == Z_STREAM_END)
|
327
|
-
if (err == Z_NEED_DICT)
|
328
|
-
if (d_stream.adler != @@dictId)
|
329
|
-
puts("unexpected dictionary")
|
330
|
-
exit(1)
|
331
|
-
end
|
332
|
-
err = inflateSetDictionary(d_stream, @@dictionary,@@dictionary.length)
|
333
|
-
|
334
|
-
end
|
335
|
-
CHECK_ERR(err, "inflate with dict")
|
336
|
-
end
|
337
|
-
|
338
|
-
err = inflateEnd(d_stream)
|
339
|
-
CHECK_ERR(err, "inflateEnd")
|
340
|
-
uncompr = uncompr[0,d_stream.total_out]
|
341
|
-
if uncompr != @@hello
|
342
|
-
puts("bad inflate with dict")
|
343
|
-
exit(1)
|
344
|
-
else
|
345
|
-
puts("inflate with dictionary: #{uncompr}")
|
346
|
-
end
|
347
|
-
end
|
348
|
-
|
349
|
-
comprLen = 10000*4
|
350
|
-
uncomprLen = comprLen
|
351
|
-
myVersion = ZLIB_VERSION
|
352
|
-
|
353
|
-
if (zlibVersion[0] != myVersion[0])
|
354
|
-
puts("incompatible zlib version")
|
355
|
-
exit(1)
|
356
|
-
elsif (zlibVersion != ZLIB_VERSION)
|
357
|
-
puts("warning: different zlib version")
|
358
|
-
end
|
359
|
-
|
360
|
-
compr = 0.chr * comprLen
|
361
|
-
uncompr = 0.chr * uncomprLen
|
362
|
-
if (compr.nil? || uncompr.nil?)
|
363
|
-
puts("out of memory")
|
364
|
-
exit(1)
|
365
|
-
end
|
366
|
-
test_compress(compr, comprLen, uncompr, uncomprLen)
|
367
|
-
|
368
|
-
test_gzio((ARGV.length > 0 ? ARGV[0] : TESTFILE),
|
369
|
-
uncompr, uncomprLen)
|
370
|
-
|
371
|
-
test_deflate(compr, comprLen)
|
372
|
-
test_inflate(compr, comprLen, uncompr, uncomprLen)
|
373
|
-
test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
374
|
-
test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
375
|
-
|
376
|
-
test_flush(compr, comprLen)
|
377
|
-
|
378
|
-
test_sync(compr, comprLen, uncompr, uncomprLen)
|
379
|
-
comprLen = uncomprLen
|
380
|
-
|
381
|
-
test_dict_deflate(compr, comprLen)
|
382
|
-
test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
383
|
-
|
384
|
-
|
385
|
-
|
1
|
+
# example.rb -- usage example of the zlib compression library
|
2
|
+
# Copyright (C) 1995-2004 Jean-loup Gailly.
|
3
|
+
# For conditions of distribution and use, see copyright notice in rbzlib.rb
|
4
|
+
#
|
5
|
+
# Ruby translation by Park Heesob
|
6
|
+
|
7
|
+
require 'rbzlib'
|
8
|
+
include Rbzlib
|
9
|
+
|
10
|
+
def CHECK_ERR(err,msg)
|
11
|
+
if(err != Z_OK)
|
12
|
+
raise RuntimeError,"#{msg} error: #{err}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
TESTFILE = "foo.gz"
|
17
|
+
@@hello = "hello, hello!\0"
|
18
|
+
|
19
|
+
@@dictionary = "hello"
|
20
|
+
|
21
|
+
def test_compress(compr, comprLen, uncompr, uncomprLen)
|
22
|
+
len = @@hello.length
|
23
|
+
|
24
|
+
err,comprLen = compress(compr, comprLen, @@hello, len)
|
25
|
+
CHECK_ERR(err, "compress")
|
26
|
+
compr = compr[0,comprLen]
|
27
|
+
uncompr[0,7] = "garbage"
|
28
|
+
err,uncomprLen = uncompress(uncompr, uncomprLen, compr, comprLen)
|
29
|
+
CHECK_ERR(err, "uncompress")
|
30
|
+
uncompr = uncompr[0,uncomprLen]
|
31
|
+
if uncompr != @@hello
|
32
|
+
puts("bad uncompress")
|
33
|
+
exit(1)
|
34
|
+
else
|
35
|
+
puts("uncompress(): #{uncompr}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_gzio(fname, uncompr, uncomprLen)
|
40
|
+
len = @@hello.length
|
41
|
+
err = 0
|
42
|
+
file = gzopen(fname, "wb")
|
43
|
+
if file.nil?
|
44
|
+
puts("gzopen error")
|
45
|
+
exit(1)
|
46
|
+
end
|
47
|
+
gzputc(file, 'h')
|
48
|
+
if (gzputs(file, "ello") != 4)
|
49
|
+
puts("gzputs err: #{gzerror(file, err)}")
|
50
|
+
exit(1)
|
51
|
+
end
|
52
|
+
if (gzputs(file, ", hello!") != 8)
|
53
|
+
puts("gzputs err: #{gzerror(file, err)}")
|
54
|
+
exit(1)
|
55
|
+
end
|
56
|
+
gzseek(file, 1, SEEK_CUR)
|
57
|
+
gzclose(file)
|
58
|
+
|
59
|
+
file = gzopen(fname, "rb")
|
60
|
+
if file.nil?
|
61
|
+
puts("gzopen error")
|
62
|
+
exit(1)
|
63
|
+
end
|
64
|
+
uncompr[0,7] = "garbage"
|
65
|
+
if (gzread(file, uncompr, uncomprLen) != len)
|
66
|
+
puts("gzread err: #{gzerror(file, err)}")
|
67
|
+
exit(1)
|
68
|
+
end
|
69
|
+
uncompr = uncompr[0,len]
|
70
|
+
if uncompr != @@hello
|
71
|
+
puts("bad gzread: #{uncompr}")
|
72
|
+
exit(1)
|
73
|
+
else
|
74
|
+
puts("gzread(): #{uncompr}")
|
75
|
+
end
|
76
|
+
pos = gzseek(file, -8, SEEK_CUR)
|
77
|
+
if (pos != 6 || gztell(file) != pos)
|
78
|
+
puts("gzseek error, pos=#{pos}, gztell=#{gztell(file)}")
|
79
|
+
exit(1)
|
80
|
+
end
|
81
|
+
|
82
|
+
if (gzgetc(file) != ' ')
|
83
|
+
puts("gzgetc error")
|
84
|
+
exit(1)
|
85
|
+
end
|
86
|
+
|
87
|
+
if (gzungetc(' ', file) != ' ')
|
88
|
+
puts("gzungetc error")
|
89
|
+
exit(1)
|
90
|
+
end
|
91
|
+
|
92
|
+
gzgets(file, uncompr, uncomprLen)
|
93
|
+
uncompr.chop!
|
94
|
+
if uncompr.length != 7
|
95
|
+
puts("gzgets err after gzseek: #{gzerror(file, err)}")
|
96
|
+
exit(1)
|
97
|
+
end
|
98
|
+
|
99
|
+
if uncompr != @@hello[6..-2]
|
100
|
+
puts("bad gzgets after gzseek")
|
101
|
+
exit(1)
|
102
|
+
else
|
103
|
+
puts("gzgets() after gzseek: #{uncompr}")
|
104
|
+
end
|
105
|
+
|
106
|
+
gzclose(file)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_deflate(compr, comprLen)
|
110
|
+
c_stream = Z_stream.new
|
111
|
+
len = @@hello.length
|
112
|
+
|
113
|
+
err = deflateInit(c_stream, Z_DEFAULT_COMPRESSION)
|
114
|
+
CHECK_ERR(err, "deflateInit")
|
115
|
+
|
116
|
+
c_stream.next_in = Bytef.new(@@hello)
|
117
|
+
c_stream.next_out = Bytef.new(compr)
|
118
|
+
|
119
|
+
while (c_stream.total_in != len && c_stream.total_out < comprLen)
|
120
|
+
c_stream.avail_in = c_stream.avail_out = 1
|
121
|
+
err = deflate(c_stream, Z_NO_FLUSH)
|
122
|
+
CHECK_ERR(err, "deflate")
|
123
|
+
end
|
124
|
+
while true
|
125
|
+
c_stream.avail_out = 1
|
126
|
+
err = deflate(c_stream, Z_FINISH)
|
127
|
+
break if (err == Z_STREAM_END)
|
128
|
+
CHECK_ERR(err, "deflate")
|
129
|
+
end
|
130
|
+
|
131
|
+
err = deflateEnd(c_stream)
|
132
|
+
CHECK_ERR(err, "deflateEnd")
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_inflate(compr, comprLen, uncompr, uncomprLen)
|
136
|
+
uncompr[0,7] = "garbage"
|
137
|
+
d_stream = Z_stream.new
|
138
|
+
|
139
|
+
d_stream.next_in = Bytef.new(compr)
|
140
|
+
d_stream.avail_in = 0
|
141
|
+
d_stream.next_out = Bytef.new(uncompr)
|
142
|
+
|
143
|
+
err = inflateInit(d_stream)
|
144
|
+
CHECK_ERR(err, "inflateInit")
|
145
|
+
|
146
|
+
while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
|
147
|
+
d_stream.avail_in = d_stream.avail_out = 1
|
148
|
+
err = inflate(d_stream, Z_NO_FLUSH)
|
149
|
+
break if (err == Z_STREAM_END)
|
150
|
+
CHECK_ERR(err, "inflate")
|
151
|
+
end
|
152
|
+
|
153
|
+
err = inflateEnd(d_stream)
|
154
|
+
CHECK_ERR(err, "inflateEnd")
|
155
|
+
uncompr = uncompr[0,d_stream.total_out]
|
156
|
+
if uncompr != @@hello
|
157
|
+
puts("bad inflate")
|
158
|
+
exit(1)
|
159
|
+
else
|
160
|
+
puts("inflate(): #{uncompr}")
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
165
|
+
c_stream = Z_stream.new
|
166
|
+
err = deflateInit(c_stream, Z_BEST_SPEED)
|
167
|
+
CHECK_ERR(err, "deflateInit")
|
168
|
+
|
169
|
+
c_stream.next_out = Bytef.new(compr)
|
170
|
+
c_stream.avail_out = comprLen
|
171
|
+
c_stream.next_in = Bytef.new(uncompr)
|
172
|
+
c_stream.avail_in = uncomprLen
|
173
|
+
err = deflate(c_stream, Z_NO_FLUSH)
|
174
|
+
CHECK_ERR(err, "deflate")
|
175
|
+
if c_stream.avail_in.nonzero?
|
176
|
+
puts("deflate not greedy")
|
177
|
+
exit(1)
|
178
|
+
end
|
179
|
+
|
180
|
+
deflateParams(c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY)
|
181
|
+
c_stream.next_in = Bytef.new(compr)
|
182
|
+
c_stream.avail_in = comprLen/2
|
183
|
+
err = deflate(c_stream, Z_NO_FLUSH)
|
184
|
+
CHECK_ERR(err, "deflate")
|
185
|
+
|
186
|
+
deflateParams(c_stream, Z_BEST_COMPRESSION, Z_FILTERED)
|
187
|
+
c_stream.next_in = Bytef.new(uncompr)
|
188
|
+
c_stream.avail_in = uncomprLen
|
189
|
+
err = deflate(c_stream, Z_NO_FLUSH)
|
190
|
+
CHECK_ERR(err, "deflate")
|
191
|
+
|
192
|
+
err = deflate(c_stream, Z_FINISH)
|
193
|
+
if (err != Z_STREAM_END)
|
194
|
+
puts("deflate should report Z_STREAM_END")
|
195
|
+
exit(1)
|
196
|
+
end
|
197
|
+
err = deflateEnd(c_stream)
|
198
|
+
CHECK_ERR(err, "deflateEnd")
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
202
|
+
d_stream = Z_stream.new
|
203
|
+
uncompr[0,7] = "garbage"
|
204
|
+
|
205
|
+
d_stream.next_in = Bytef.new(compr)
|
206
|
+
d_stream.avail_in = comprLen
|
207
|
+
|
208
|
+
err = inflateInit(d_stream)
|
209
|
+
CHECK_ERR(err, "inflateInit")
|
210
|
+
|
211
|
+
while true
|
212
|
+
d_stream.next_out = Bytef.new(uncompr)
|
213
|
+
d_stream.avail_out = uncomprLen
|
214
|
+
err = inflate(d_stream, Z_NO_FLUSH)
|
215
|
+
break if (err == Z_STREAM_END)
|
216
|
+
CHECK_ERR(err, "large inflate")
|
217
|
+
end
|
218
|
+
|
219
|
+
err = inflateEnd(d_stream)
|
220
|
+
CHECK_ERR(err, "inflateEnd")
|
221
|
+
|
222
|
+
if (d_stream.total_out != 2*uncomprLen + comprLen/2)
|
223
|
+
puts("bad large inflate: #{d_stream.total_out}")
|
224
|
+
exit(1)
|
225
|
+
else
|
226
|
+
puts("large_inflate(): OK")
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_flush(compr, comprLen)
|
231
|
+
c_stream = Z_stream.new
|
232
|
+
len = @@hello.length
|
233
|
+
|
234
|
+
err = deflateInit(c_stream, Z_DEFAULT_COMPRESSION)
|
235
|
+
CHECK_ERR(err, "deflateInit")
|
236
|
+
|
237
|
+
c_stream.next_in = Bytef.new(@@hello)
|
238
|
+
c_stream.next_out = Bytef.new(compr)
|
239
|
+
c_stream.avail_in = 3
|
240
|
+
c_stream.avail_out = comprLen
|
241
|
+
err = deflate(c_stream, Z_FULL_FLUSH)
|
242
|
+
CHECK_ERR(err, "deflate")
|
243
|
+
|
244
|
+
compr[3]=(compr[3].ord+1).chr
|
245
|
+
c_stream.avail_in = len - 3
|
246
|
+
|
247
|
+
err = deflate(c_stream, Z_FINISH)
|
248
|
+
if (err != Z_STREAM_END)
|
249
|
+
CHECK_ERR(err, "deflate")
|
250
|
+
end
|
251
|
+
err = deflateEnd(c_stream)
|
252
|
+
CHECK_ERR(err, "deflateEnd")
|
253
|
+
|
254
|
+
comprLen = c_stream.total_out
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_sync(compr, comprLen, uncompr, uncomprLen)
|
258
|
+
d_stream = Z_stream.new
|
259
|
+
uncompr[0,7] = "garbage"
|
260
|
+
|
261
|
+
d_stream.next_in = Bytef.new(compr)
|
262
|
+
d_stream.avail_in = 2
|
263
|
+
|
264
|
+
err = inflateInit(d_stream)
|
265
|
+
CHECK_ERR(err, "inflateInit")
|
266
|
+
|
267
|
+
d_stream.next_out = Bytef.new(uncompr)
|
268
|
+
d_stream.avail_out = uncomprLen
|
269
|
+
|
270
|
+
inflate(d_stream, Z_NO_FLUSH)
|
271
|
+
CHECK_ERR(err, "inflate")
|
272
|
+
|
273
|
+
d_stream.avail_in = comprLen-2
|
274
|
+
err = inflateSync(d_stream)
|
275
|
+
CHECK_ERR(err, "inflateSync")
|
276
|
+
|
277
|
+
err = inflate(d_stream, Z_FINISH)
|
278
|
+
if (err != Z_DATA_ERROR)
|
279
|
+
puts("inflate should report DATA_ERROR")
|
280
|
+
exit(1)
|
281
|
+
end
|
282
|
+
err = inflateEnd(d_stream)
|
283
|
+
uncompr = uncompr[0,d_stream.total_out]
|
284
|
+
CHECK_ERR(err, "inflateEnd")
|
285
|
+
puts("after inflateSync(): hel#{uncompr}")
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_dict_deflate(compr, comprLen)
|
289
|
+
c_stream = Z_stream.new
|
290
|
+
err = deflateInit(c_stream, Z_BEST_COMPRESSION)
|
291
|
+
CHECK_ERR(err, "deflateInit")
|
292
|
+
|
293
|
+
err = deflateSetDictionary(c_stream,@@dictionary, @@dictionary.length)
|
294
|
+
CHECK_ERR(err, "deflateSetDictionary")
|
295
|
+
|
296
|
+
@@dictId = c_stream.adler
|
297
|
+
c_stream.next_out = Bytef.new(compr)
|
298
|
+
c_stream.avail_out = comprLen
|
299
|
+
|
300
|
+
c_stream.next_in = Bytef.new(@@hello)
|
301
|
+
c_stream.avail_in = @@hello.length
|
302
|
+
|
303
|
+
err = deflate(c_stream, Z_FINISH)
|
304
|
+
if (err != Z_STREAM_END)
|
305
|
+
puts("deflate should report Z_STREAM_END")
|
306
|
+
exit(1)
|
307
|
+
end
|
308
|
+
err = deflateEnd(c_stream)
|
309
|
+
CHECK_ERR(err, "deflateEnd")
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
313
|
+
d_stream = Z_stream.new
|
314
|
+
uncompr[0,7] = "garbage"
|
315
|
+
|
316
|
+
d_stream.next_in = Bytef.new(compr)
|
317
|
+
d_stream.avail_in = comprLen
|
318
|
+
|
319
|
+
err = inflateInit(d_stream)
|
320
|
+
CHECK_ERR(err, "inflateInit")
|
321
|
+
d_stream.next_out = Bytef.new(uncompr)
|
322
|
+
d_stream.avail_out = uncomprLen
|
323
|
+
|
324
|
+
while true
|
325
|
+
err = inflate(d_stream, Z_NO_FLUSH)
|
326
|
+
break if (err == Z_STREAM_END)
|
327
|
+
if (err == Z_NEED_DICT)
|
328
|
+
if (d_stream.adler != @@dictId)
|
329
|
+
puts("unexpected dictionary")
|
330
|
+
exit(1)
|
331
|
+
end
|
332
|
+
err = inflateSetDictionary(d_stream, @@dictionary,@@dictionary.length)
|
333
|
+
|
334
|
+
end
|
335
|
+
CHECK_ERR(err, "inflate with dict")
|
336
|
+
end
|
337
|
+
|
338
|
+
err = inflateEnd(d_stream)
|
339
|
+
CHECK_ERR(err, "inflateEnd")
|
340
|
+
uncompr = uncompr[0,d_stream.total_out]
|
341
|
+
if uncompr != @@hello
|
342
|
+
puts("bad inflate with dict")
|
343
|
+
exit(1)
|
344
|
+
else
|
345
|
+
puts("inflate with dictionary: #{uncompr}")
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
comprLen = 10000*4
|
350
|
+
uncomprLen = comprLen
|
351
|
+
myVersion = ZLIB_VERSION
|
352
|
+
|
353
|
+
if (zlibVersion[0] != myVersion[0])
|
354
|
+
puts("incompatible zlib version")
|
355
|
+
exit(1)
|
356
|
+
elsif (zlibVersion != ZLIB_VERSION)
|
357
|
+
puts("warning: different zlib version")
|
358
|
+
end
|
359
|
+
|
360
|
+
compr = 0.chr * comprLen
|
361
|
+
uncompr = 0.chr * uncomprLen
|
362
|
+
if (compr.nil? || uncompr.nil?)
|
363
|
+
puts("out of memory")
|
364
|
+
exit(1)
|
365
|
+
end
|
366
|
+
test_compress(compr, comprLen, uncompr, uncomprLen)
|
367
|
+
|
368
|
+
test_gzio((ARGV.length > 0 ? ARGV[0] : TESTFILE),
|
369
|
+
uncompr, uncomprLen)
|
370
|
+
|
371
|
+
test_deflate(compr, comprLen)
|
372
|
+
test_inflate(compr, comprLen, uncompr, uncomprLen)
|
373
|
+
test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
374
|
+
test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
375
|
+
|
376
|
+
test_flush(compr, comprLen)
|
377
|
+
|
378
|
+
test_sync(compr, comprLen, uncompr, uncomprLen)
|
379
|
+
comprLen = uncomprLen
|
380
|
+
|
381
|
+
test_dict_deflate(compr, comprLen)
|
382
|
+
test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
383
|
+
|
384
|
+
|
385
|
+
|