pr-zlib 1.0.0 → 1.0.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.
data/lib/pr/zlib.rb CHANGED
@@ -9,7 +9,7 @@ include Rbzlib
9
9
  module Zlib
10
10
 
11
11
  RUBY_ZLIB_VERSION = '0.6.0'
12
- PR_ZLIB_VERSION = '1.0.0'
12
+ PR_ZLIB_VERSION = '1.0.1'
13
13
 
14
14
  class Error < StandardError
15
15
  end
@@ -88,7 +88,7 @@ module Zlib
88
88
 
89
89
  def raise_zlib_error(err, msg)
90
90
  msg = zError(err) if msg.nil? || msg==''
91
-
91
+
92
92
  case err
93
93
  when Z_STREAM_END
94
94
  raise StreamEnd, msg
@@ -110,7 +110,7 @@ module Zlib
110
110
  raise Error, "unknown zlib error #errend: #msgend"
111
111
  end
112
112
  end
113
-
113
+
114
114
  def zstream_expand_buffer()
115
115
  if @buf.nil?
116
116
  @buf = Bytef.new(0.chr * ZSTREAM_INITIAL_BUFSIZE)
@@ -483,15 +483,15 @@ module Zlib
483
483
 
484
484
  def finish()
485
485
  @z.zstream_run("", 0, Z_FINISH)
486
- dst = @z.zstream_detach_buffer()
486
+ @z.zstream_detach_buffer()
487
487
  end
488
488
 
489
489
  def flush_next_in
490
- dst = @z.zstream_detach_input
490
+ @z.zstream_detach_input
491
491
  end
492
492
 
493
493
  def flush_next_out
494
- dst = @z.zstream_detach_buffer
494
+ @z.zstream_detach_buffer
495
495
  end
496
496
 
497
497
  def initialize
@@ -558,7 +558,7 @@ module Zlib
558
558
 
559
559
  def deflate(src,flush=Z_NO_FLUSH)
560
560
  do_deflate(src,flush)
561
- dst = @z.zstream_detach_buffer
561
+ @z.zstream_detach_buffer
562
562
  end
563
563
 
564
564
  def <<(src)
@@ -570,7 +570,7 @@ module Zlib
570
570
  if(v_flush != Z_NO_FLUSH)
571
571
  @z.zstream_run("", 0, flush)
572
572
  end
573
- dst = @z.zstream_detach_buffer()
573
+ @z.zstream_detach_buffer()
574
574
  end
575
575
 
576
576
  def params(level=Z_DEFAULT_COMPRESSION,strategy=Z_DEFAULT_STRATEGY)
@@ -1111,7 +1111,7 @@ module Zlib
1111
1111
  gzfile_write(str, str.length)
1112
1112
  str.length
1113
1113
  end
1114
-
1114
+
1115
1115
  def putc(ch)
1116
1116
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
1117
1117
  gzfile_write(ch.chr, 1)
@@ -1281,7 +1281,7 @@ module Zlib
1281
1281
  end
1282
1282
 
1283
1283
  def readline(rs=$/)
1284
- dst = gets(rs)
1284
+ gets(rs)
1285
1285
  end
1286
1286
 
1287
1287
  def each(rs=$/)
@@ -1343,7 +1343,7 @@ module Zlib
1343
1343
  return nil if @gz.z.input.nil?
1344
1344
  @gz.z.input.dup
1345
1345
  end
1346
-
1346
+
1347
1347
  def rscheck(rsptr,rslen,rs)
1348
1348
  raise RuntimeError, "rs modified" if rs != rsptr
1349
1349
  end
@@ -1385,10 +1385,10 @@ module Zlib
1385
1385
  gzfile_read_more()
1386
1386
  ap = n - rslen
1387
1387
  end
1388
-
1388
+
1389
1389
  rscheck(rsptr, rslen, rs) if (!rspara)
1390
1390
  res = @gz.z.buf.buffer[ap,@gz.z.buf.offset - n + 1].index(rsptr[0])
1391
-
1391
+
1392
1392
  if res.nil?
1393
1393
  n = @gz.z.buf.offset + 1
1394
1394
  else
@@ -1417,12 +1417,12 @@ module Zlib
1417
1417
  return ""
1418
1418
  end
1419
1419
 
1420
- while (!@gz.z.ZSTREAM_IS_FINISHED() && @gz.z.buf.offset < len)
1420
+ while (!@gz.z.ZSTREAM_IS_FINISHED() && @gz.z.buf.offset < len)
1421
1421
  gzfile_read_more()
1422
1422
  end
1423
1423
 
1424
- if (GZFILE_IS_FINISHED(@gz))
1425
- if (@gz.z.flags & GZFILE_FLAG_FOOTER_FINISHED).zero?
1424
+ if (GZFILE_IS_FINISHED(@gz))
1425
+ if (@gz.z.flags & GZFILE_FLAG_FOOTER_FINISHED).zero?
1426
1426
  gzfile_check_footer()
1427
1427
  end
1428
1428
  return nil
data/pr-zlib.gemspec CHANGED
@@ -1,28 +1,22 @@
1
1
  require 'rubygems'
2
2
 
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'pr-zlib'
5
- gem.version = '1.0.0'
6
- gem.authors = ['Park Heesob', 'Daniel Berger']
7
- gem.email = 'phasis@gmail.com'
8
- gem.homepage = 'http://www.rubyforge.org/projects/pure'
9
- gem.rubyforge_project = 'pure'
10
- gem.platform = Gem::Platform::RUBY
11
- gem.summary = 'Pure Ruby version of the zlib library'
12
- gem.test_files = Dir['test/*.rb']
13
- gem.has_rdoc = true
14
- gem.files = Dir["**/*"].reject{ |f| f.include?('SVN') }
15
- gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'pr-zlib'
5
+ spec.version = '1.0.1'
6
+ spec.authors = ['Park Heesob', 'Daniel Berger']
7
+ spec.email = 'phasis@gmail.com'
8
+ spec.homepage = 'https://github.com/djberg96/pr-zlib'
9
+ spec.summary = 'Pure Ruby version of the zlib library'
10
+ spec.test_files = Dir['test/*.rb']
11
+ spec.files = Dir["**/*"].reject{ |f| f.include?('git') }
12
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
13
 
17
- gem.add_dependency('test-unit', '>= 2.0.2')
14
+ spec.add_development_dependency('test-unit', '>= 2.4.0')
15
+ spec.add_development_dependency('ruby-prof')
18
16
 
19
- gem.description = <<-EOF
20
- The pr-zlib library is a pure Ruby implementation of both the zlib C
21
- library, and the Ruby zlib interface that ships as part of the standard
22
- library.
23
- EOF
24
- end
25
-
26
- if $0 == __FILE__
27
- Gem::Builder.new(spec).build
17
+ spec.description = <<-EOF
18
+ The pr-zlib library is a pure Ruby implementation of both the zlib C
19
+ library, and the Ruby zlib interface that ships as part of the standard
20
+ library.
21
+ EOF
28
22
  end
@@ -0,0 +1,43 @@
1
+ ########################################################################
2
+ # This benchmarks the zlib library that ships as part of the Ruby
3
+ # standard library.
4
+ #
5
+ # You can run this benchmark via the bench:przlib Rake task.
6
+ ########################################################################
7
+ require 'pr/zlib'
8
+ require 'benchmark'
9
+
10
+ print "\n\n== Running the benchmarks for pr-zlib ==\n\n"
11
+
12
+ # First, let's create a ~7 MB text file.
13
+
14
+ FILE_NAME = "benchmark.txt"
15
+ GZ_FILE_NAME = "benchmark.txt.gz"
16
+
17
+ File.open(FILE_NAME, "w") do |fh|
18
+ 10000.times{ |x|
19
+ s = "Now is the time for #{x} good men to come to the aid of their country."
20
+ fh.puts s
21
+ }
22
+ end
23
+
24
+ Benchmark.bm do |x|
25
+ x.report("write") do
26
+ 5.times{
27
+ Zlib::GzipWriter.open(GZ_FILE_NAME) do |gz|
28
+ gz.write(File.read(FILE_NAME))
29
+ end
30
+ }
31
+ end
32
+
33
+ x.report("read") do
34
+ 5.times{
35
+ Zlib::GzipReader.open(GZ_FILE_NAME) do |gz|
36
+ gz.read
37
+ end
38
+ }
39
+ end
40
+ end
41
+
42
+ File.delete(FILE_NAME) if File.exists?(FILE_NAME)
43
+ File.delete(GZ_FILE_NAME) if File.exists?(GZ_FILE_NAME)
@@ -0,0 +1,43 @@
1
+ ########################################################################
2
+ # This benchmarks the zlib library that ships as part of the Ruby
3
+ # standard library.
4
+ #
5
+ # You can run this benchmark via the bench-zlib Rake task.
6
+ ########################################################################
7
+ require 'zlib'
8
+ require 'benchmark'
9
+
10
+ print "\n\n== Running the benchmarks for zlib (stdlib) ==\n\n"
11
+
12
+ # First, let's create a ~7 MB text file.
13
+
14
+ FILE_NAME = "benchmark.txt"
15
+ GZ_FILE_NAME = "benchmark.txt.gz"
16
+
17
+ File.open(FILE_NAME, "w") do |fh|
18
+ 10000.times{ |x|
19
+ s = "Now is the time for #{x} good men to come to the aid of their country."
20
+ fh.puts s
21
+ }
22
+ end
23
+
24
+ Benchmark.bm do |x|
25
+ x.report("write") do
26
+ 5.times{
27
+ Zlib::GzipWriter.open(GZ_FILE_NAME) do |gz|
28
+ gz.write(File.read(FILE_NAME))
29
+ end
30
+ }
31
+ end
32
+
33
+ x.report("read") do
34
+ 5.times{
35
+ Zlib::GzipReader.open(GZ_FILE_NAME) do |gz|
36
+ gz.read
37
+ end
38
+ }
39
+ end
40
+ end
41
+
42
+ File.delete(FILE_NAME) if File.exists?(FILE_NAME)
43
+ File.delete(GZ_FILE_NAME) if File.exists?(GZ_FILE_NAME)
@@ -0,0 +1,28 @@
1
+ require 'pr/zlib'
2
+
3
+ FILE_NAME = 'zlib_temp.txt'
4
+ GZ_FILE_NAME = 'zlib_temp.txt.gz'
5
+
6
+ # Create a text file to use first.
7
+ File.open(FILE_NAME, "w") do |fh|
8
+ 1000.times{ |x|
9
+ s = "Now is the time for #{x} good men to come to the aid of their country."
10
+ fh.puts s
11
+ }
12
+ end
13
+
14
+ Zlib::GzipWriter.open(GZ_FILE_NAME){ |gz| gz.write(IO.read(FILE_NAME)) }
15
+
16
+ require 'ruby-prof'
17
+
18
+ result = RubyProf.profile do
19
+ Zlib::GzipReader.open(GZ_FILE_NAME) do |gz|
20
+ gz.read
21
+ end
22
+ end
23
+
24
+ File.delete(FILE_NAME) if File.exists?(FILE_NAME)
25
+ File.delete(GZ_FILE_NAME) if File.exists?(GZ_FILE_NAME)
26
+
27
+ printer = RubyProf::FlatPrinter.new(result)
28
+ printer.print(STDOUT)
@@ -0,0 +1,26 @@
1
+ require 'pr/zlib'
2
+
3
+ FILE_NAME = 'zlib_temp.txt'
4
+ GZ_FILE_NAME = 'zlib_temp.txt.gz'
5
+
6
+ # Create a text file to use first.
7
+ File.open(FILE_NAME, "w") do |fh|
8
+ 1000.times{ |x|
9
+ s = "Now is the time for #{x} good men to come to the aid of their country."
10
+ fh.puts s
11
+ }
12
+ end
13
+
14
+ require 'ruby-prof'
15
+
16
+ result = RubyProf.profile do
17
+ Zlib::GzipWriter.open(GZ_FILE_NAME) do |gz|
18
+ gz.write(File.read(FILE_NAME))
19
+ end
20
+ end
21
+
22
+ File.delete(FILE_NAME) if File.exists?(FILE_NAME)
23
+ File.delete(GZ_FILE_NAME) if File.exists?(GZ_FILE_NAME)
24
+
25
+ printer = RubyProf::FlatPrinter.new(result)
26
+ printer.print(STDOUT)
data/test/test_rbzlib.rb CHANGED
@@ -3,134 +3,131 @@
3
3
  #
4
4
  # Test case for the Rbzlib module.
5
5
  ########################################################################
6
- require 'rubygems'
7
- gem 'test-unit'
8
-
9
6
  require 'pr/rbzlib'
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
 
12
9
  class TC_Rbzlib < Test::Unit::TestCase
13
- include Rbzlib
14
-
15
- def setup
16
- @fixnum = 7
17
- @buffer = 0.chr * 16
18
- end
19
-
20
- def test_version
21
- assert_equal('1.2.3', ZLIB_VERSION)
22
- end
23
-
24
- def test_fixnum_ord
25
- assert_respond_to(7, :ord)
26
- assert_equal(7, 7.ord)
27
- end
28
-
29
- def test_misc_constants
30
- assert_equal(9, MAX_MEM_LEVEL)
31
- assert_equal(8, DEF_MEM_LEVEL)
32
- assert_equal(15, MAX_WBITS)
33
- assert_equal(MAX_WBITS, DEF_WBITS)
34
- assert_equal(0, STORED_BLOCK)
35
- assert_equal(1, STATIC_TREES)
36
- assert_equal(2, DYN_TREES)
37
- assert_equal(3, MIN_MATCH)
38
- assert_equal(258, MAX_MATCH)
39
- assert_equal(0x20, PRESET_DICT)
40
- assert_equal(65521, BASE)
41
- assert_equal(5552, NMAX)
42
- assert_equal(0, OS_CODE)
43
- assert_equal(1, SEEK_CUR)
44
- assert_equal(2, SEEK_END)
45
- end
46
-
47
- def test_sync_contants
48
- assert_equal(0, Z_NO_FLUSH)
49
- assert_equal(1, Z_PARTIAL_FLUSH)
50
- assert_equal(2, Z_SYNC_FLUSH)
51
- assert_equal(3, Z_FULL_FLUSH)
52
- assert_equal(4, Z_FINISH)
53
- assert_equal(5, Z_BLOCK)
54
- end
55
-
56
- def test_stream_constants
57
- assert_equal(0, Z_OK)
58
- assert_equal(1, Z_STREAM_END)
59
- assert_equal(2, Z_NEED_DICT)
60
- assert_equal(-1, Z_ERRNO)
61
- assert_equal(-1, Z_EOF)
62
- assert_equal(-2, Z_STREAM_ERROR)
63
- assert_equal(-3, Z_DATA_ERROR)
64
- assert_equal(-4, Z_MEM_ERROR)
65
- assert_equal(-5, Z_BUF_ERROR)
66
- assert_equal(-6, Z_VERSION_ERROR)
67
- assert_equal(16384, Z_BUFSIZE)
68
- end
69
-
70
- def test_compression_constants
71
- assert_equal(0, Z_NO_COMPRESSION)
72
- assert_equal(1, Z_BEST_SPEED)
73
- assert_equal(9, Z_BEST_COMPRESSION)
74
- assert_equal(-1, Z_DEFAULT_COMPRESSION)
75
- assert_equal(8, Z_DEFLATED)
76
- end
77
-
78
- def test_encoding_constants
79
- assert_equal(1, Z_FILTERED)
80
- assert_equal(2, Z_HUFFMAN_ONLY)
81
- assert_equal(3, Z_RLE)
82
- assert_equal(4, Z_FIXED)
83
- assert_equal(0, Z_DEFAULT_STRATEGY)
84
- end
85
-
86
- def test_crc_constants
87
- assert_equal(0x01, ASCII_FLAG)
88
- assert_equal(0x02, HEAD_CRC)
89
- assert_equal(0x04, EXTRA_FIELD)
90
- assert_equal(0x08, ORIG_NAME)
91
- assert_equal(0x10, COMMENT_)
92
- assert_equal(0xE0, RESERVED)
93
- end
94
-
95
- def test_zError
96
- assert_respond_to(self, :zError)
97
- assert_equal('stream end', self.zError(Z_STREAM_END))
98
- end
99
-
100
- def test_zlibVersion
101
- assert_respond_to(self, :zlibVersion)
102
- assert_equal(ZLIB_VERSION, self.zlibVersion)
103
- end
104
-
105
- def test_z_error
106
- assert_respond_to(self, :z_error)
107
- assert_raise(RuntimeError){ self.z_error('hello') }
108
- end
109
-
110
- def test_adler32
111
- assert_respond_to(Rbzlib, :adler32)
112
- assert_equal(1, Rbzlib.adler32(32, nil))
113
- assert_equal(0, Rbzlib.adler32(0, @buffer))
114
- assert_equal(1048577, Rbzlib.adler32(1, @buffer))
115
- assert_equal(10485770, Rbzlib.adler32(10, @buffer))
116
- assert_equal(33554464, Rbzlib.adler32(32, @buffer))
117
- end
118
-
119
- def test_adler32_expected_errors
120
- assert_raise(ArgumentError){ Rbzlib.adler32 }
121
- assert_raise(ArgumentError){ Rbzlib.adler32('test') }
122
- end
123
-
124
- def test_get_crc_table
125
- assert_respond_to(Rbzlib, :get_crc_table)
126
- end
127
-
128
- def test_gz_open
129
- assert_respond_to(Rbzlib, :gz_open)
130
- end
131
-
132
- def teardown
133
- @fixnum = 0
134
- @buffer = nil
135
- end
10
+ include Rbzlib
11
+
12
+ def setup
13
+ @fixnum = 7
14
+ @buffer = 0.chr * 16
15
+ end
16
+
17
+ def test_version
18
+ assert_equal('1.2.3', ZLIB_VERSION)
19
+ end
20
+
21
+ def test_fixnum_ord
22
+ assert_respond_to(7, :ord)
23
+ assert_equal(7, 7.ord)
24
+ end
25
+
26
+ def test_misc_constants
27
+ assert_equal(9, MAX_MEM_LEVEL)
28
+ assert_equal(8, DEF_MEM_LEVEL)
29
+ assert_equal(15, MAX_WBITS)
30
+ assert_equal(MAX_WBITS, DEF_WBITS)
31
+ assert_equal(0, STORED_BLOCK)
32
+ assert_equal(1, STATIC_TREES)
33
+ assert_equal(2, DYN_TREES)
34
+ assert_equal(3, MIN_MATCH)
35
+ assert_equal(258, MAX_MATCH)
36
+ assert_equal(0x20, PRESET_DICT)
37
+ assert_equal(65521, BASE)
38
+ assert_equal(5552, NMAX)
39
+ assert_equal(0, OS_CODE)
40
+ assert_equal(1, SEEK_CUR)
41
+ assert_equal(2, SEEK_END)
42
+ end
43
+
44
+ def test_sync_contants
45
+ assert_equal(0, Z_NO_FLUSH)
46
+ assert_equal(1, Z_PARTIAL_FLUSH)
47
+ assert_equal(2, Z_SYNC_FLUSH)
48
+ assert_equal(3, Z_FULL_FLUSH)
49
+ assert_equal(4, Z_FINISH)
50
+ assert_equal(5, Z_BLOCK)
51
+ end
52
+
53
+ def test_stream_constants
54
+ assert_equal(0, Z_OK)
55
+ assert_equal(1, Z_STREAM_END)
56
+ assert_equal(2, Z_NEED_DICT)
57
+ assert_equal(-1, Z_ERRNO)
58
+ assert_equal(-1, Z_EOF)
59
+ assert_equal(-2, Z_STREAM_ERROR)
60
+ assert_equal(-3, Z_DATA_ERROR)
61
+ assert_equal(-4, Z_MEM_ERROR)
62
+ assert_equal(-5, Z_BUF_ERROR)
63
+ assert_equal(-6, Z_VERSION_ERROR)
64
+ assert_equal(16384, Z_BUFSIZE)
65
+ end
66
+
67
+ def test_compression_constants
68
+ assert_equal(0, Z_NO_COMPRESSION)
69
+ assert_equal(1, Z_BEST_SPEED)
70
+ assert_equal(9, Z_BEST_COMPRESSION)
71
+ assert_equal(-1, Z_DEFAULT_COMPRESSION)
72
+ assert_equal(8, Z_DEFLATED)
73
+ end
74
+
75
+ def test_encoding_constants
76
+ assert_equal(1, Z_FILTERED)
77
+ assert_equal(2, Z_HUFFMAN_ONLY)
78
+ assert_equal(3, Z_RLE)
79
+ assert_equal(4, Z_FIXED)
80
+ assert_equal(0, Z_DEFAULT_STRATEGY)
81
+ end
82
+
83
+ def test_crc_constants
84
+ assert_equal(0x01, ASCII_FLAG)
85
+ assert_equal(0x02, HEAD_CRC)
86
+ assert_equal(0x04, EXTRA_FIELD)
87
+ assert_equal(0x08, ORIG_NAME)
88
+ assert_equal(0x10, COMMENT_)
89
+ assert_equal(0xE0, RESERVED)
90
+ end
91
+
92
+ def test_zError
93
+ assert_respond_to(self, :zError)
94
+ assert_equal('stream end', self.zError(Z_STREAM_END))
95
+ end
96
+
97
+ def test_zlibVersion
98
+ assert_respond_to(self, :zlibVersion)
99
+ assert_equal(ZLIB_VERSION, self.zlibVersion)
100
+ end
101
+
102
+ def test_z_error
103
+ assert_respond_to(self, :z_error)
104
+ assert_raise(RuntimeError){ self.z_error('hello') }
105
+ end
106
+
107
+ def test_adler32
108
+ assert_respond_to(Rbzlib, :adler32)
109
+ assert_equal(1, Rbzlib.adler32(32, nil))
110
+ assert_equal(0, Rbzlib.adler32(0, @buffer))
111
+ assert_equal(1048577, Rbzlib.adler32(1, @buffer))
112
+ assert_equal(10485770, Rbzlib.adler32(10, @buffer))
113
+ assert_equal(33554464, Rbzlib.adler32(32, @buffer))
114
+ end
115
+
116
+ def test_adler32_expected_errors
117
+ assert_raise(ArgumentError){ Rbzlib.adler32 }
118
+ assert_raise(ArgumentError){ Rbzlib.adler32('test') }
119
+ end
120
+
121
+ def test_get_crc_table
122
+ assert_respond_to(Rbzlib, :get_crc_table)
123
+ end
124
+
125
+ def test_gz_open
126
+ assert_respond_to(Rbzlib, :gz_open)
127
+ end
128
+
129
+ def teardown
130
+ @fixnum = 0
131
+ @buffer = nil
132
+ end
136
133
  end