rbzip2 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -1
  3. data/README.md +73 -37
  4. data/Rakefile +2 -0
  5. data/lib/core_ext/io.rb +12 -0
  6. data/lib/rbzip2.rb +13 -9
  7. data/lib/rbzip2/adapter.rb +17 -0
  8. data/lib/rbzip2/ffi.rb +33 -0
  9. data/lib/rbzip2/ffi/compressor.rb +85 -0
  10. data/lib/rbzip2/ffi/constants.rb +30 -0
  11. data/lib/rbzip2/ffi/decompressor.rb +163 -0
  12. data/lib/rbzip2/ffi/errors.rb +14 -0
  13. data/lib/rbzip2/io.rb +19 -5
  14. data/lib/rbzip2/java.rb +23 -0
  15. data/lib/rbzip2/java/compressor.rb +38 -0
  16. data/lib/rbzip2/java/decompressor.rb +65 -0
  17. data/lib/rbzip2/ruby.rb +18 -0
  18. data/lib/rbzip2/{compressor.rb → ruby/compressor.rb} +141 -191
  19. data/lib/rbzip2/{constants.rb → ruby/constants.rb} +2 -2
  20. data/lib/rbzip2/ruby/crc.rb +70 -0
  21. data/lib/rbzip2/{decompressor.rb → ruby/decompressor.rb} +107 -127
  22. data/lib/rbzip2/{input_data.rb → ruby/input_data.rb} +8 -18
  23. data/lib/rbzip2/{output_data.rb → ruby/output_data.rb} +6 -9
  24. data/lib/rbzip2/version.rb +2 -2
  25. data/spec/common/compressor_spec.rb +68 -0
  26. data/spec/common/decompressor_spec.rb +63 -0
  27. data/spec/ffi/compressor_spec.rb +12 -0
  28. data/spec/ffi/decompressor_spec.rb +12 -0
  29. data/spec/java/compressor_spec.rb +12 -0
  30. data/spec/java/decompressor_spec.rb +12 -0
  31. data/spec/ruby/compressor_spec.rb +12 -0
  32. data/spec/ruby/decompressor_spec.rb +12 -0
  33. metadata +56 -149
  34. data/.gemtest +0 -0
  35. data/.gitignore +0 -3
  36. data/.travis.yml +0 -9
  37. data/Gemfile +0 -3
  38. data/Gemfile.lock +0 -28
  39. data/lib/rbzip2/crc.rb +0 -105
  40. data/rbzip2.gemspec +0 -27
  41. data/spec/compressor_spec.rb +0 -42
  42. data/spec/decompressor_spec.rb +0 -41
  43. data/spec/fixtures/big_test.bz2 +0 -0
  44. data/spec/fixtures/big_test.txt +0 -2018
  45. data/spec/fixtures/test.bz2 +0 -0
  46. data/spec/fixtures/test.txt +0 -11
  47. data/spec/helper.rb +0 -12
@@ -1,11 +1,11 @@
1
1
  # This code is free software; you can redistribute it and/or modify it under
2
2
  # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2011, Sebastian Staudt
4
+ # Copyright (c) 2011-2017, Sebastian Staudt
5
5
 
6
- class RBzip2::InputData
6
+ class RBzip2::Ruby::InputData
7
7
 
8
- include RBzip2::Constants
8
+ include RBzip2::Ruby::Constants
9
9
 
10
10
  attr_reader :base, :cftab, :get_and_move_to_front_decode_yy, :in_use,
11
11
  :limit, :ll8, :min_lens, :perm, :receive_decoding_tables_pos,
@@ -21,31 +21,21 @@ class RBzip2::InputData
21
21
 
22
22
  @unzftab = Array.new 256, 0
23
23
 
24
- @base = Array.new N_GROUPS
25
- N_GROUPS.times { |i| @base[i] = Array.new(MAX_ALPHA_SIZE, 0) }
26
- @limit = Array.new N_GROUPS
27
- N_GROUPS.times { |i| @limit[i] = Array.new(MAX_ALPHA_SIZE, 0) }
28
- @perm = Array.new N_GROUPS
29
- N_GROUPS.times { |i| @perm[i] = Array.new(MAX_ALPHA_SIZE, 0) }
24
+ @base = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
25
+ @limit = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
26
+ @perm = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
30
27
  @min_lens = Array.new N_GROUPS, 0
31
28
 
32
29
  @cftab = Array.new 257, 0
33
30
  @get_and_move_to_front_decode_yy = Array.new 256
34
- @temp_char_array_2d = Array.new N_GROUPS
35
- N_GROUPS.times { |i| @temp_char_array_2d[i] = Array.new(MAX_ALPHA_SIZE, 0) }
31
+ @temp_char_array_2d = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
36
32
  @receive_decoding_tables_pos = Array.new N_GROUPS, 0
37
33
 
38
34
  @ll8 = Array.new block_size * BASEBLOCKSIZE
39
35
  end
40
36
 
41
37
  def init_tt(size)
42
- tt_shadow = @tt
43
-
44
- if tt_shadow.nil? || tt_shadow.size < size
45
- @tt = tt_shadow = Array.new(size)
46
- end
47
-
48
- tt_shadow
38
+ @tt = Array.new(size) if @tt.nil? || @tt.size < size
49
39
  end
50
40
 
51
41
  end
@@ -1,11 +1,11 @@
1
1
  # This code is free software; you can redistribute it and/or modify it under
2
2
  # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2011, Sebastian Staudt
4
+ # Copyright (c) 2011-2013, Sebastian Staudt
5
5
 
6
- class RBzip2::OutputData
6
+ class RBzip2::Ruby::OutputData
7
7
 
8
- include RBzip2::Constants
8
+ include RBzip2::Ruby::Constants
9
9
 
10
10
  attr_reader :block, :ftab, :fmap, :generate_mtf_values_yy, :heap, :in_use,
11
11
  :main_sort_big_done, :main_sort_copy, :main_sort_running_order,
@@ -30,14 +30,11 @@ class RBzip2::OutputData
30
30
  @unseq_to_seq = Array.new 256
31
31
 
32
32
  @generate_mtf_values_yy = Array.new 256
33
- @send_mtf_values_code = Array.new N_GROUPS
34
- N_GROUPS.times { |i| @send_mtf_values_code[i] = Array.new MAX_ALPHA_SIZE }
33
+ @send_mtf_values_code = Array.new(N_GROUPS) { Array.new MAX_ALPHA_SIZE }
35
34
  @send_mtf_values_cost = Array.new N_GROUPS
36
35
  @send_mtf_values_fave = Array.new N_GROUPS
37
- @send_mtf_values_len = Array.new N_GROUPS
38
- N_GROUPS.times { |i| @send_mtf_values_len[i] = Array.new MAX_ALPHA_SIZE }
39
- @send_mtf_values_rfreq = Array.new N_GROUPS
40
- N_GROUPS.times { |i| @send_mtf_values_rfreq[i] = Array.new MAX_ALPHA_SIZE, 0 }
36
+ @send_mtf_values_len = Array.new(N_GROUPS) { Array.new MAX_ALPHA_SIZE }
37
+ @send_mtf_values_rfreq = Array.new(N_GROUPS) { Array.new MAX_ALPHA_SIZE }
41
38
  @send_mtf_values2_pos = Array.new N_GROUPS
42
39
  @send_mtf_values4_in_use_16 = Array.new 16
43
40
 
@@ -1,10 +1,10 @@
1
1
  # This code is free software; you can redistribute it and/or modify it under
2
2
  # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2011, Sebastian Staudt
4
+ # Copyright (c) 2011-2017, Sebastian Staudt
5
5
 
6
6
  module RBzip2
7
7
 
8
- VERSION = '0.2.0' unless const_defined? :VERSION
8
+ VERSION = '0.3.0' unless const_defined? :VERSION
9
9
 
10
10
  end
@@ -0,0 +1,68 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2017, Sebastian Staudt
5
+
6
+ require 'base64'
7
+
8
+ require 'helper'
9
+
10
+ shared_examples_for 'a compressor' do
11
+
12
+ before do
13
+ @io = StringIO.new
14
+ @bz2_compressor = described_class.new @io
15
+ end
16
+
17
+ it 'acts like a standard IO' do
18
+ methods = described_class.instance_methods.map &:to_sym
19
+ expect(methods).to include(:close, :putc, :puts, :write)
20
+ end
21
+
22
+ it 'should be able to compress raw data' do
23
+ txt_file = fixture 'fixtures/test.txt'
24
+ bz2_file = fixture 'fixtures/test.bz2'
25
+ @bz2_compressor.write txt_file.read
26
+ @bz2_compressor.close
27
+
28
+ expect(@io.string).to eq(bz2_file.read)
29
+ end
30
+
31
+ it 'should be able to compress large raw data' do
32
+ txt_file = fixture 'fixtures/big_test.txt'
33
+ suffix = '.' + described_class.name.split('::')[1].downcase
34
+ suffix = '' if suffix == '.ffi'
35
+ bz2_file = fixture "fixtures/big_test#{suffix}.bz2"
36
+ @bz2_compressor.write txt_file.read
37
+ @bz2_compressor.close
38
+
39
+ expect(@io.string).to eq(bz2_file.read)
40
+ end
41
+
42
+ it 'should be able to compress a single character' do
43
+ @bz2_compressor.putc 'T'
44
+ @bz2_compressor.putc 'e'
45
+ @bz2_compressor.putc 's'
46
+ @bz2_compressor.putc 't'
47
+ @bz2_compressor.close
48
+
49
+ base64_result = Base64.encode64 @io.string
50
+
51
+ expect(`echo "#{base64_result}" | base64 --decode | bzcat`).to eq('Test')
52
+ end
53
+
54
+ it 'should be able to compress a line of text' do
55
+ @bz2_compressor.puts 'Test 1'
56
+ @bz2_compressor.puts 'Test 2'
57
+ @bz2_compressor.close
58
+
59
+ base64_result = Base64.encode64 @io.string
60
+
61
+ expect(`echo "#{base64_result}" | base64 --decode | bzcat`).to eq("Test 1#{$/}Test 2#{$/}")
62
+ end
63
+
64
+ after do
65
+ @bz2_compressor.close unless @bz2_compressor.nil?
66
+ end
67
+
68
+ end
@@ -0,0 +1,63 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2017, Sebastian Staudt
5
+
6
+ require 'helper'
7
+
8
+ shared_examples_for 'a decompressor' do
9
+
10
+ it 'acts like a standard IO' do
11
+ methods = described_class.instance_methods.map { |m| m.to_sym }
12
+ expect(methods).to include(:close, :getc, :gets, :read)
13
+ end
14
+
15
+ it 'knows its size' do
16
+ bz2_file = fixture 'fixtures/test.bz2'
17
+ bz2_decompressor = described_class.new bz2_file
18
+
19
+ expect(bz2_decompressor.size).to eq(375)
20
+ end
21
+
22
+ it 'knows the size of the uncompressed data' do
23
+ bz2_file = fixture 'fixtures/test.bz2'
24
+ bz2_decompressor = described_class.new bz2_file
25
+
26
+ expect(bz2_decompressor.uncompressed).to eq(704)
27
+ end
28
+
29
+ it 'should be able to decompress compressed data' do
30
+ bz2_file = fixture 'fixtures/test.bz2'
31
+ bz2_decompressor = described_class.new bz2_file
32
+ txt_file = fixture 'fixtures/test.txt'
33
+
34
+ expect(bz2_decompressor.read).to eq(txt_file.read)
35
+ end
36
+
37
+ it 'should be able to decompress large compressed data' do
38
+ txt_file = fixture 'fixtures/big_test.txt'
39
+ bz2_file = fixture 'fixtures/big_test.bz2'
40
+ bz2_decompressor = described_class.new bz2_file
41
+
42
+ expect(bz2_decompressor.read).to eq(txt_file.read)
43
+ end
44
+
45
+ it 'should be able to decompress a single character from compressed data' do
46
+ bz2_file = fixture 'fixtures/test.bz2'
47
+ bz2_decompressor = described_class.new bz2_file
48
+
49
+ expect(bz2_decompressor.getc).to eq('T')
50
+ expect(bz2_decompressor.getc).to eq('h')
51
+ expect(bz2_decompressor.getc).to eq('i')
52
+ expect(bz2_decompressor.getc).to eq('s')
53
+ expect(bz2_decompressor.getc).to eq(' ')
54
+ end
55
+
56
+ it 'should be able to decompress a single line from compressed data' do
57
+ bz2_file = fixture 'fixtures/test.bz2'
58
+ bz2_decompressor = described_class.new bz2_file
59
+
60
+ expect(bz2_decompressor.gets).to eq("This is a test fixture for RBzip2.\n")
61
+ end
62
+
63
+ end
@@ -0,0 +1,12 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2013-2017, Sebastian Staudt
5
+
6
+ require 'helper'
7
+
8
+ describe RBzip2::FFI::Compressor do
9
+
10
+ it_behaves_like 'a compressor'
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2013-2017, Sebastian Staudt
5
+
6
+ require 'helper'
7
+
8
+ describe RBzip2::FFI::Decompressor do
9
+
10
+ it_behaves_like 'a decompressor'
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2013-2017, Sebastian Staudt
5
+
6
+ require 'helper'
7
+
8
+ describe RBzip2::Java::Compressor do
9
+
10
+ it_behaves_like 'a compressor'
11
+
12
+ end if java?
@@ -0,0 +1,12 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2013-2017, Sebastian Staudt
5
+
6
+ require 'helper'
7
+
8
+ describe RBzip2::Java::Decompressor do
9
+
10
+ it_behaves_like 'a decompressor'
11
+
12
+ end if java?
@@ -0,0 +1,12 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2011-2017, Sebastian Staudt
5
+
6
+ require 'helper'
7
+
8
+ describe RBzip2::Ruby::Compressor do
9
+
10
+ it_behaves_like 'a compressor'
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2011-2017, Sebastian Staudt
5
+
6
+ require 'helper'
7
+
8
+ describe RBzip2::Ruby::Decompressor do
9
+
10
+ it_behaves_like 'a decompressor'
11
+
12
+ end
metadata CHANGED
@@ -1,175 +1,82 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rbzip2
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Sebastian Staudt
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-11-11 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- type: :development
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ~>
26
- - !ruby/object:Gem::Version
27
- hash: 55
28
- segments:
29
- - 0
30
- - 10
31
- - 0
32
- version: 0.10.0
33
- prerelease: false
34
- name: mocha
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- type: :development
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 63
44
- segments:
45
- - 0
46
- - 9
47
- - 2
48
- version: 0.9.2
49
- prerelease: false
50
- name: rake
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- type: :development
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 17
60
- segments:
61
- - 2
62
- - 7
63
- - 1
64
- version: 2.7.1
65
- prerelease: false
66
- name: rspec-core
67
- version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- type: :development
70
- requirement: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 19
76
- segments:
77
- - 2
78
- - 7
79
- - 0
80
- version: 2.7.0
81
- prerelease: false
82
- name: rspec-expectations
83
- version_requirements: *id004
84
- - !ruby/object:Gem::Dependency
85
- type: :development
86
- requirement: &id005 !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
89
- - - ~>
90
- - !ruby/object:Gem::Version
91
- hash: 5
92
- segments:
93
- - 0
94
- - 7
95
- - 3
96
- version: 0.7.3
97
- prerelease: false
98
- name: yard
99
- version_requirements: *id005
100
- description: A pure Ruby implementation of the bzip2 compression algorithm.
101
- email:
11
+ date: 2017-02-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Various bzip2 implementations for Ruby.
14
+ email:
102
15
  - koraktor@gmail.com
103
16
  executables: []
104
-
105
17
  extensions: []
106
-
107
18
  extra_rdoc_files: []
108
-
109
- files:
110
- - .gemtest
111
- - .gitignore
112
- - .travis.yml
113
- - Gemfile
114
- - Gemfile.lock
19
+ files:
115
20
  - LICENSE
116
21
  - README.md
117
22
  - Rakefile
23
+ - lib/core_ext/io.rb
118
24
  - lib/rbzip2.rb
119
- - lib/rbzip2/compressor.rb
120
- - lib/rbzip2/constants.rb
121
- - lib/rbzip2/crc.rb
122
- - lib/rbzip2/decompressor.rb
123
- - lib/rbzip2/input_data.rb
25
+ - lib/rbzip2/adapter.rb
26
+ - lib/rbzip2/ffi.rb
27
+ - lib/rbzip2/ffi/compressor.rb
28
+ - lib/rbzip2/ffi/constants.rb
29
+ - lib/rbzip2/ffi/decompressor.rb
30
+ - lib/rbzip2/ffi/errors.rb
124
31
  - lib/rbzip2/io.rb
125
- - lib/rbzip2/output_data.rb
32
+ - lib/rbzip2/java.rb
33
+ - lib/rbzip2/java/compressor.rb
34
+ - lib/rbzip2/java/decompressor.rb
35
+ - lib/rbzip2/ruby.rb
36
+ - lib/rbzip2/ruby/compressor.rb
37
+ - lib/rbzip2/ruby/constants.rb
38
+ - lib/rbzip2/ruby/crc.rb
39
+ - lib/rbzip2/ruby/decompressor.rb
40
+ - lib/rbzip2/ruby/input_data.rb
41
+ - lib/rbzip2/ruby/output_data.rb
126
42
  - lib/rbzip2/version.rb
127
- - rbzip2.gemspec
128
- - spec/compressor_spec.rb
129
- - spec/decompressor_spec.rb
130
- - spec/fixtures/big_test.bz2
131
- - spec/fixtures/big_test.txt
132
- - spec/fixtures/test.bz2
133
- - spec/fixtures/test.txt
134
- - spec/helper.rb
43
+ - spec/common/compressor_spec.rb
44
+ - spec/common/decompressor_spec.rb
45
+ - spec/ffi/compressor_spec.rb
46
+ - spec/ffi/decompressor_spec.rb
47
+ - spec/java/compressor_spec.rb
48
+ - spec/java/decompressor_spec.rb
49
+ - spec/ruby/compressor_spec.rb
50
+ - spec/ruby/decompressor_spec.rb
135
51
  homepage: https://github.com/koraktor/rbzip2
136
52
  licenses: []
137
-
53
+ metadata: {}
138
54
  post_install_message:
139
55
  rdoc_options: []
140
-
141
- require_paths:
56
+ require_paths:
142
57
  - lib
143
- required_ruby_version: !ruby/object:Gem::Requirement
144
- none: false
145
- requirements:
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
146
60
  - - ">="
147
- - !ruby/object:Gem::Version
148
- hash: 3
149
- segments:
150
- - 0
151
- version: "0"
152
- required_rubygems_version: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
155
65
  - - ">="
156
- - !ruby/object:Gem::Version
157
- hash: 3
158
- segments:
159
- - 0
160
- version: "0"
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
161
68
  requirements: []
162
-
163
69
  rubyforge_project:
164
- rubygems_version: 1.8.11
70
+ rubygems_version: 2.6.10
165
71
  signing_key:
166
- specification_version: 3
167
- summary: Pure Ruby impementation of bzip2
168
- test_files:
169
- - spec/compressor_spec.rb
170
- - spec/decompressor_spec.rb
171
- - spec/fixtures/big_test.bz2
172
- - spec/fixtures/big_test.txt
173
- - spec/fixtures/test.bz2
174
- - spec/fixtures/test.txt
175
- - spec/helper.rb
72
+ specification_version: 4
73
+ summary: bzip2 for Ruby
74
+ test_files:
75
+ - spec/common/compressor_spec.rb
76
+ - spec/common/decompressor_spec.rb
77
+ - spec/ffi/compressor_spec.rb
78
+ - spec/ffi/decompressor_spec.rb
79
+ - spec/java/compressor_spec.rb
80
+ - spec/java/decompressor_spec.rb
81
+ - spec/ruby/compressor_spec.rb
82
+ - spec/ruby/decompressor_spec.rb