brianmario-bzip2-ruby 0.2.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.
- data/History.txt +5 -0
- data/README.rdoc +30 -0
- data/Rakefile +19 -0
- data/VERSION.yml +4 -0
- data/bzip2-ruby.gemspec +50 -0
- data/ext/bz2.c +1582 -0
- data/ext/extconf.rb +13 -0
- data/tasks/extconf/bz2.rake +43 -0
- data/tasks/extconf.rake +13 -0
- data/test/reader.rb +370 -0
- data/test/runit_.rb +32 -0
- data/test/writer.rb +152 -0
- metadata +67 -0
data/ext/extconf.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'mkmf'
|
3
|
+
dir_config('bz2')
|
4
|
+
have_header('bzlib.h')
|
5
|
+
|
6
|
+
if have_library("bz2", "BZ2_bzWriteOpen")
|
7
|
+
if enable_config("shared", true)
|
8
|
+
$static = nil
|
9
|
+
end
|
10
|
+
create_makefile("bzip2")
|
11
|
+
else
|
12
|
+
puts "libbz2 not found, maybe try manually specifying --with-bz2-dir to find it?"
|
13
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
namespace :extconf do
|
2
|
+
extension = File.basename(__FILE__, '.rake')
|
3
|
+
|
4
|
+
ext = "ext/#{extension}"
|
5
|
+
ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
|
6
|
+
ext_files = FileList[
|
7
|
+
"#{ext}/*.c",
|
8
|
+
"#{ext}/*.h",
|
9
|
+
"#{ext}/*.rl",
|
10
|
+
"#{ext}/extconf.rb",
|
11
|
+
"#{ext}/Makefile",
|
12
|
+
# "lib"
|
13
|
+
]
|
14
|
+
|
15
|
+
|
16
|
+
task :compile => extension do
|
17
|
+
if Dir.glob("**/#{extension}.{o,so,dll}").length == 0
|
18
|
+
STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
19
|
+
STDERR.puts "Gem actually failed to build. Your system is"
|
20
|
+
STDERR.puts "NOT configured properly to build #{GEM_NAME}."
|
21
|
+
STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Builds just the #{extension} extension"
|
27
|
+
task extension.to_sym => ["#{ext}/Makefile", ext_so ]
|
28
|
+
|
29
|
+
file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
|
30
|
+
Dir.chdir(ext) do ruby "extconf.rb" end
|
31
|
+
end
|
32
|
+
|
33
|
+
file ext_so => ext_files do
|
34
|
+
Dir.chdir(ext) do
|
35
|
+
sh(PLATFORM =~ /win32/ ? 'nmake' : 'make') do |ok, res|
|
36
|
+
if !ok
|
37
|
+
require "fileutils"
|
38
|
+
FileUtils.rm Dir.glob('*.{so,o,dll,bundle}')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/tasks/extconf.rake
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
namespace :extconf do
|
2
|
+
desc "Compiles the Ruby extension"
|
3
|
+
task :compile
|
4
|
+
end
|
5
|
+
|
6
|
+
task :compile => "extconf:compile"
|
7
|
+
|
8
|
+
task :test => :compile
|
9
|
+
|
10
|
+
BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp}"
|
11
|
+
$hoe.clean_globs |= ["ext/**/#{BIN}", "lib/**/#{BIN}", 'ext/**/Makefile']
|
12
|
+
$hoe.spec.require_paths = Dir['{lib,ext/*}']
|
13
|
+
$hoe.spec.extensions = FileList["ext/**/extconf.rb"].to_a
|
data/test/reader.rb
ADDED
@@ -0,0 +1,370 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# This is the test from rubicon
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(*%w{.. tests})
|
6
|
+
require 'rubygems'
|
7
|
+
require 'bzip2'
|
8
|
+
require 'runit_'
|
9
|
+
|
10
|
+
Inh = defined?(RUNIT) ? RUNIT : Test::Unit
|
11
|
+
|
12
|
+
$file = "_10lines_"
|
13
|
+
$data = [
|
14
|
+
"00: This is a line\n",
|
15
|
+
"01: This is a line\n",
|
16
|
+
"02: This is a line\n",
|
17
|
+
"03: This is a line\n",
|
18
|
+
"04: This is a line\n",
|
19
|
+
"05: This is a line\n",
|
20
|
+
"06: This is a line\n",
|
21
|
+
"07: This is a line\n",
|
22
|
+
"08: This is a line\n",
|
23
|
+
"09: This is a line\n"
|
24
|
+
]
|
25
|
+
|
26
|
+
open("|bzip2 > #$file", "w") do |f|
|
27
|
+
$data.each { |l| f.puts l }
|
28
|
+
end
|
29
|
+
|
30
|
+
class TestReader < Inh::TestCase
|
31
|
+
|
32
|
+
SAMPLE = "08: This is a line\n"
|
33
|
+
|
34
|
+
def test_f_s_foreach
|
35
|
+
count = 0
|
36
|
+
Bzip2::Reader.foreach($file) do |line|
|
37
|
+
num = line[0..1].to_i
|
38
|
+
assert_equal(count, num)
|
39
|
+
count += 1
|
40
|
+
end
|
41
|
+
assert_equal($data.size, count)
|
42
|
+
|
43
|
+
count = 0
|
44
|
+
Bzip2::Reader.foreach($file, nil) do |file|
|
45
|
+
file.split(/\n/).each do |line|
|
46
|
+
num = line[0..1].to_i
|
47
|
+
assert_equal(count, num)
|
48
|
+
count += 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
assert_equal($data.size, count)
|
52
|
+
|
53
|
+
count = 0
|
54
|
+
Bzip2::Reader.foreach($file, ' ') do |thing|
|
55
|
+
count += 1
|
56
|
+
end
|
57
|
+
assert_equal(41, count)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_f_s_readlines
|
61
|
+
lines = Bzip2::Reader.readlines($file)
|
62
|
+
assert_equal($data.size, lines.size)
|
63
|
+
|
64
|
+
lines = Bzip2::Reader.readlines($file, nil)
|
65
|
+
assert_equal(1, lines.size)
|
66
|
+
assert_equal(SAMPLE.length * $data.size, lines[0].size)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_f_closed?
|
70
|
+
f = Bzip2::Reader.open($file)
|
71
|
+
assert(!f.closed?)
|
72
|
+
f.close
|
73
|
+
assert(f.closed?)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_f_each
|
77
|
+
count = 0
|
78
|
+
Bzip2::Reader.open($file) do |file|
|
79
|
+
file.each do |line|
|
80
|
+
num = line[0..1].to_i
|
81
|
+
assert_equal(count, num)
|
82
|
+
count += 1
|
83
|
+
end
|
84
|
+
assert_equal($data.size, count)
|
85
|
+
end
|
86
|
+
|
87
|
+
count = 0
|
88
|
+
Bzip2::Reader.open($file) do |file|
|
89
|
+
file.each(nil) do |contents|
|
90
|
+
contents.split(/\n/).each do |line|
|
91
|
+
num = line[0..1].to_i
|
92
|
+
assert_equal(count, num)
|
93
|
+
count += 1
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
assert_equal($data.size, count)
|
98
|
+
|
99
|
+
count = 0
|
100
|
+
Bzip2::Reader.open($file) do |file|
|
101
|
+
file.each(' ') do |thing|
|
102
|
+
count += 1
|
103
|
+
end
|
104
|
+
end
|
105
|
+
assert_equal(41, count)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_f_each_byte
|
109
|
+
count = 0
|
110
|
+
data = $data.join
|
111
|
+
|
112
|
+
Bzip2::Reader.open($file) do |file|
|
113
|
+
file.each_byte do |b|
|
114
|
+
assert_equal(data[count], b)
|
115
|
+
count += 1
|
116
|
+
end
|
117
|
+
end
|
118
|
+
assert_equal(SAMPLE.length * $data.size, count)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_f_each_line
|
122
|
+
count = 0
|
123
|
+
Bzip2::Reader.open($file) do |file|
|
124
|
+
file.each_line do |line|
|
125
|
+
num = line[0..1].to_i
|
126
|
+
assert_equal(count, num)
|
127
|
+
count += 1
|
128
|
+
end
|
129
|
+
assert_equal($data.size, count)
|
130
|
+
end
|
131
|
+
|
132
|
+
count = 0
|
133
|
+
Bzip2::Reader.open($file) do |file|
|
134
|
+
file.each_line(nil) do |contents|
|
135
|
+
contents.split(/\n/).each do |line|
|
136
|
+
num = line[0..1].to_i
|
137
|
+
assert_equal(count, num)
|
138
|
+
count += 1
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
assert_equal($data.size, count)
|
143
|
+
|
144
|
+
count = 0
|
145
|
+
Bzip2::Reader.open($file) do |file|
|
146
|
+
file.each_line(' ') do |thing|
|
147
|
+
count += 1
|
148
|
+
end
|
149
|
+
end
|
150
|
+
assert_equal(41, count)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_f_eof
|
154
|
+
Bzip2::Reader.open($file) do |file|
|
155
|
+
$data.size.times do
|
156
|
+
assert(!file.eof)
|
157
|
+
assert(!file.eof?)
|
158
|
+
file.gets
|
159
|
+
end
|
160
|
+
assert(file.eof)
|
161
|
+
assert(file.eof?)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_f_getc
|
166
|
+
count = 0
|
167
|
+
data = $data.join
|
168
|
+
|
169
|
+
Bzip2::Reader.open($file) do |file|
|
170
|
+
while (ch = file.getc)
|
171
|
+
assert_equal(data[count], ch)
|
172
|
+
count += 1
|
173
|
+
end
|
174
|
+
assert_equal(nil, file.getc)
|
175
|
+
end
|
176
|
+
assert_equal(SAMPLE.length * $data.size, count)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_f_gets
|
180
|
+
count = 0
|
181
|
+
Bzip2::Reader.open($file) do |file|
|
182
|
+
while (line = file.gets)
|
183
|
+
num = line[0..1].to_i
|
184
|
+
assert_equal(count, num)
|
185
|
+
count += 1
|
186
|
+
end
|
187
|
+
assert_equal(nil, file.gets)
|
188
|
+
assert_equal($data.size, count)
|
189
|
+
end
|
190
|
+
|
191
|
+
count = 0
|
192
|
+
Bzip2::Reader.open($file) do |file|
|
193
|
+
while (line = file.gets("line\n"))
|
194
|
+
assert_equal($data[count], line)
|
195
|
+
num = line[0..1].to_i
|
196
|
+
assert_equal(count, num)
|
197
|
+
count += 1
|
198
|
+
end
|
199
|
+
assert_equal(nil, file.gets)
|
200
|
+
assert_equal($data.size, count)
|
201
|
+
end
|
202
|
+
|
203
|
+
count = 0
|
204
|
+
Bzip2::Reader.open($file) do |file|
|
205
|
+
while (contents = file.gets(nil))
|
206
|
+
contents.split(/\n/).each do |line|
|
207
|
+
num = line[0..1].to_i
|
208
|
+
assert_equal(count, num)
|
209
|
+
count += 1
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
assert_equal($data.size, count)
|
214
|
+
|
215
|
+
count = 0
|
216
|
+
Bzip2::Reader.open($file) do |file|
|
217
|
+
while (thing = file.gets(' '))
|
218
|
+
count += 1
|
219
|
+
end
|
220
|
+
end
|
221
|
+
assert_equal(41, count)
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_f_read
|
225
|
+
Bzip2::Reader.open($file) do |file|
|
226
|
+
content = file.read
|
227
|
+
assert_equal(SAMPLE.length * $data.size, content.length)
|
228
|
+
count = 0
|
229
|
+
content.split(/\n/).each do |line|
|
230
|
+
num = line[0..1].to_i
|
231
|
+
assert_equal(count, num)
|
232
|
+
count += 1
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
Bzip2::Reader.open($file) do |file|
|
237
|
+
assert_equal("00: This is ", file.read(12))
|
238
|
+
assert_equal("a line\n01: T", file.read(12))
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_f_readchar
|
243
|
+
count = 0
|
244
|
+
data = $data.join
|
245
|
+
Bzip2::Reader.open($file) do |file|
|
246
|
+
190.times do |count|
|
247
|
+
ch = file.readchar
|
248
|
+
assert_equal(data[count], ch)
|
249
|
+
count += 1
|
250
|
+
end
|
251
|
+
assert_raises(Bzip2::EOZError) { file.readchar }
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_f_readline
|
256
|
+
count = 0
|
257
|
+
Bzip2::Reader.open($file) do |file|
|
258
|
+
$data.size.times do |count|
|
259
|
+
line = file.readline
|
260
|
+
num = line[0..1].to_i
|
261
|
+
assert_equal(count, num)
|
262
|
+
count += 1
|
263
|
+
end
|
264
|
+
assert_raises(Bzip2::EOZError) { file.readline }
|
265
|
+
end
|
266
|
+
|
267
|
+
count = 0
|
268
|
+
Bzip2::Reader.open($file) do |file|
|
269
|
+
contents = file.readline(nil)
|
270
|
+
contents.split(/\n/).each do |line|
|
271
|
+
num = line[0..1].to_i
|
272
|
+
assert_equal(count, num)
|
273
|
+
count += 1
|
274
|
+
end
|
275
|
+
assert_raises(Bzip2::EOZError) { file.readline }
|
276
|
+
end
|
277
|
+
assert_equal($data.size, count)
|
278
|
+
|
279
|
+
count = 0
|
280
|
+
Bzip2::Reader.open($file) do |file|
|
281
|
+
41.times do |count|
|
282
|
+
thing = file.readline(' ')
|
283
|
+
count += 1
|
284
|
+
end
|
285
|
+
assert_raises(Bzip2::EOZError) { file.readline }
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_f_readlines
|
290
|
+
Bzip2::Reader.open($file) do |file|
|
291
|
+
lines = file.readlines
|
292
|
+
assert_equal($data.size, lines.size)
|
293
|
+
end
|
294
|
+
|
295
|
+
Bzip2::Reader.open($file) do |file|
|
296
|
+
lines = file.readlines(nil)
|
297
|
+
assert_equal(1, lines.size)
|
298
|
+
assert_equal(SAMPLE.length * $data.size, lines[0].size)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_f_ungetc
|
303
|
+
Bzip2::Reader.open($file) do |file|
|
304
|
+
assert_equal(?0, file.getc)
|
305
|
+
assert_equal(?0, file.getc)
|
306
|
+
assert_equal(?:, file.getc)
|
307
|
+
assert_equal(?\s, file.getc)
|
308
|
+
assert_nil(file.ungetc(?:))
|
309
|
+
assert_equal(?:, file.getc)
|
310
|
+
1 while file.getc
|
311
|
+
assert_nil(file.ungetc(?A))
|
312
|
+
assert_equal(?A, file.getc)
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_f_ungets
|
317
|
+
count = 0
|
318
|
+
Bzip2::Reader.open($file) do |file|
|
319
|
+
assert_equal($data[count], file.gets)
|
320
|
+
assert_equal(count + 1, file.lineno);
|
321
|
+
assert_nil(file.ungets($data[count]))
|
322
|
+
assert_equal($data[count], file.gets)
|
323
|
+
count += 1
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_s_readline
|
328
|
+
count = 0
|
329
|
+
string = IO.readlines($file, nil)[0]
|
330
|
+
file = Bzip2::Reader.new(string)
|
331
|
+
$data.size.times do |count|
|
332
|
+
line = file.readline
|
333
|
+
num = line[0..1].to_i
|
334
|
+
assert_equal(count, num)
|
335
|
+
count += 1
|
336
|
+
end
|
337
|
+
assert_raises(Bzip2::EOZError) { file.readline }
|
338
|
+
file.close
|
339
|
+
|
340
|
+
count = 0
|
341
|
+
file = Bzip2::Reader.new(string)
|
342
|
+
contents = file.readline(nil)
|
343
|
+
contents.split(/\n/).each do |line|
|
344
|
+
num = line[0..1].to_i
|
345
|
+
assert_equal(count, num)
|
346
|
+
count += 1
|
347
|
+
end
|
348
|
+
assert_raises(Bzip2::EOZError) { file.readline }
|
349
|
+
assert_equal($data.size, count)
|
350
|
+
file.close
|
351
|
+
|
352
|
+
count = 0
|
353
|
+
file = Bzip2::Reader.new(string)
|
354
|
+
41.times do |count|
|
355
|
+
thing = file.readline(' ')
|
356
|
+
count += 1
|
357
|
+
end
|
358
|
+
assert_raises(Bzip2::EOZError) { file.readline }
|
359
|
+
file.close
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_zzz
|
363
|
+
File.unlink($file)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
|
368
|
+
if defined?(RUNIT)
|
369
|
+
RUNIT::CUI::TestRunner.run(TestReader.suite)
|
370
|
+
end
|
data/test/runit_.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'test/unit'
|
3
|
+
rescue LoadError
|
4
|
+
require 'runit/testcase'
|
5
|
+
require 'runit/cui/testrunner'
|
6
|
+
|
7
|
+
module RUNIT
|
8
|
+
module Assert
|
9
|
+
def assert_raises(error, message = nil)
|
10
|
+
begin
|
11
|
+
yield
|
12
|
+
rescue error
|
13
|
+
assert(true, message)
|
14
|
+
rescue
|
15
|
+
assert_fail("must fail with #{error} : #{string}")
|
16
|
+
else
|
17
|
+
assert_fail("*must* fail : #{string}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
if RUBY_VERSION > "1.7"
|
26
|
+
class Array
|
27
|
+
alias indices select
|
28
|
+
end
|
29
|
+
class Hash
|
30
|
+
alias indexes select
|
31
|
+
end
|
32
|
+
end
|
data/test/writer.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# This is the test from rubicon
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(*%w{.. tests})
|
6
|
+
require 'rubygems'
|
7
|
+
require 'bzip2'
|
8
|
+
require 'runit_'
|
9
|
+
|
10
|
+
Inh = defined?(RUNIT) ? RUNIT : Test::Unit
|
11
|
+
|
12
|
+
$file = "_10lines_"
|
13
|
+
|
14
|
+
class Dummy
|
15
|
+
def to_s
|
16
|
+
"dummy"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class TestWriter < Inh::TestCase
|
21
|
+
|
22
|
+
def test_f_LSHIFT # '<<'
|
23
|
+
Bzip2::Writer.open($file, "w") do |file|
|
24
|
+
file << 1 << "\n" << Dummy.new << "\n" << "cat\n"
|
25
|
+
end
|
26
|
+
expected = [ "1\n", "dummy\n", "cat\n"]
|
27
|
+
Bzip2::Reader.foreach($file) do |line|
|
28
|
+
assert_equal(expected.shift, line)
|
29
|
+
end
|
30
|
+
assert_equal([], expected)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_f_error
|
34
|
+
io = File.new($file, "w")
|
35
|
+
bz2 = Bzip2::Writer.new(io)
|
36
|
+
bz2 << 1 << "\n" << Dummy.new << "\n" << "cat\n"
|
37
|
+
bz = Bzip2::Reader.new($file)
|
38
|
+
assert_raises(Bzip2::Error) { bz.gets }
|
39
|
+
bz = Bzip2::Reader.open($file)
|
40
|
+
assert_raises(Bzip2::EOZError) { bz.gets }
|
41
|
+
io.close
|
42
|
+
assert_raises(IOError) { Bzip2::Reader.new(io) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_f_gets_para
|
46
|
+
Bzip2::Writer.open($file) do |file|
|
47
|
+
file.print "foo\n"*4096, "\n"*4096, "bar"*4096, "\n"*4096, "zot\n"*1024
|
48
|
+
end
|
49
|
+
Bzip2::Reader.open($file) do |file|
|
50
|
+
assert_equal("foo\n"*4096+"\n", file.gets(""))
|
51
|
+
assert_equal("bar"*4096+"\n\n", file.gets(""))
|
52
|
+
assert_equal("zot\n"*1024, file.gets(""))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_f_print
|
57
|
+
Bzip2::Writer.open($file) do |file|
|
58
|
+
file.print "hello"
|
59
|
+
file.print 1,2
|
60
|
+
$_ = "wombat\n"
|
61
|
+
file.print
|
62
|
+
$\ = ":"
|
63
|
+
$, = ","
|
64
|
+
file.print 3, 4
|
65
|
+
file.print 5, 6
|
66
|
+
$\ = nil
|
67
|
+
file.print "\n"
|
68
|
+
$, = nil
|
69
|
+
end
|
70
|
+
|
71
|
+
Bzip2::Reader.open($file) do |file|
|
72
|
+
content = file.gets(nil)
|
73
|
+
assert_equal("hello12wombat\n3,4:5,6:\n", content)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_f_putc
|
78
|
+
Bzip2::Writer.open($file, "wb") do |file|
|
79
|
+
file.putc "A"
|
80
|
+
0.upto(255) { |ch| file.putc ch }
|
81
|
+
end
|
82
|
+
|
83
|
+
Bzip2::Reader.open($file, "rb") do |file|
|
84
|
+
assert_equal(?A, file.getc)
|
85
|
+
0.upto(255) { |ch| assert_equal(ch, file.getc) }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_f_puts
|
90
|
+
Bzip2::Writer.open($file, "w") do |file|
|
91
|
+
file.puts "line 1", "line 2"
|
92
|
+
file.puts [ Dummy.new, 4 ]
|
93
|
+
end
|
94
|
+
|
95
|
+
Bzip2::Reader.open($file) do |file|
|
96
|
+
assert_equal("line 1\n", file.gets)
|
97
|
+
assert_equal("line 2\n", file.gets)
|
98
|
+
assert_equal("dummy\n", file.gets)
|
99
|
+
assert_equal("4\n", file.gets)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_f_write
|
104
|
+
Bzip2::Writer.open($file, "w") do |file|
|
105
|
+
assert_equal(10, file.write('*' * 10))
|
106
|
+
assert_equal(5, file.write('!' * 5))
|
107
|
+
assert_equal(0, file.write(''))
|
108
|
+
assert_equal(1, file.write(1))
|
109
|
+
assert_equal(3, file.write(2.30000))
|
110
|
+
assert_equal(1, file.write("\n"))
|
111
|
+
end
|
112
|
+
|
113
|
+
Bzip2::Reader.open($file) do |file|
|
114
|
+
assert_equal("**********!!!!!12.3\n", file.gets)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_s_string
|
119
|
+
file = Bzip2::Writer.new
|
120
|
+
assert_equal(10, file.write('*' * 10))
|
121
|
+
assert_equal(5, file.write('!' * 5))
|
122
|
+
assert_equal(0, file.write(''))
|
123
|
+
assert_equal(1, file.write(1))
|
124
|
+
assert_equal(3, file.write(2.30000))
|
125
|
+
assert_equal(1, file.write("\n"))
|
126
|
+
line = Bzip2::bunzip2(file.flush)
|
127
|
+
assert_equal("**********!!!!!12.3\n", line)
|
128
|
+
|
129
|
+
line = Bzip2::bunzip2(Bzip2::bzip2("**********!!!!!12.3\n"))
|
130
|
+
assert_equal("**********!!!!!12.3\n", line)
|
131
|
+
|
132
|
+
test = "foo\n"*4096 + "\n"*4096 + "bar"*4096 + "\n"*4096 + "zot\n"*1024
|
133
|
+
line = Bzip2::bunzip2(Bzip2::bzip2(test))
|
134
|
+
assert_equal(test, line)
|
135
|
+
|
136
|
+
assert(Bzip2::bzip2("aaaaaaaaa".taint).tainted?)
|
137
|
+
assert(Bzip2::bunzip2(Bzip2::bzip2("aaaaaaaaa".taint)).tainted?)
|
138
|
+
assert(!Bzip2::bzip2("aaaaaaaaa").tainted?)
|
139
|
+
assert(!Bzip2::bunzip2(Bzip2::bzip2("aaaaaaaaa")).tainted?)
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_zzz
|
144
|
+
File.unlink($file)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
if defined?(RUNIT)
|
149
|
+
RUNIT::CUI::TestRunner.run(TestWriter.suite)
|
150
|
+
end
|
151
|
+
|
152
|
+
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brianmario-bzip2-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guy Decoux
|
8
|
+
- Brian Lopez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-05-02 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description:
|
18
|
+
email: seniorlopez@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions:
|
22
|
+
- ext/extconf.rb
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- History.txt
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION.yml
|
30
|
+
- bzip2-ruby.gemspec
|
31
|
+
- ext/bz2.c
|
32
|
+
- ext/extconf.rb
|
33
|
+
- tasks/extconf.rake
|
34
|
+
- tasks/extconf/bz2.rake
|
35
|
+
- test/reader.rb
|
36
|
+
- test/runit_.rb
|
37
|
+
- test/writer.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/brianmario/bzip2-ruby
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --charset=UTF-8
|
43
|
+
require_paths:
|
44
|
+
- ext
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.2.0
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Ruby C bindings to libbzip2.
|
64
|
+
test_files:
|
65
|
+
- test/reader.rb
|
66
|
+
- test/runit_.rb
|
67
|
+
- test/writer.rb
|