rsmaz 0.0.3 → 0.0.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.
@@ -1,3 +1,9 @@
1
+ == 0.0.4 2011-03-26
2
+
3
+ * Text forced to binary for a consistent Ruby 1.9 experience (Hongli Lai)
4
+ * Dependency on hoe removed (Peter Cooper)
5
+ * Switched from RSpec to MiniTest
6
+
1
7
  == 0.0.3 2009-04-02
2
8
 
3
9
  * Now produces same output as reference smaz implementation
@@ -5,21 +5,23 @@
5
5
 
6
6
  == DESCRIPTION:
7
7
 
8
- Short String Compression for Ruby.
8
+ Short String Compression for Ruby.
9
9
 
10
- RSmaz is a pure-Ruby port of the Smaz short string compression
11
- algorithm by Salvatore Sanfilippo and released as a C library at:
12
- http://github.com/antirez/smaz/tree/master
13
-
14
- I've done some initial cleanup of a pure Ruby->C port, but this
15
- is not yet complete. It does pass the specs, however! Feel free
16
- to clean it up as it's a bit memory inefficient right now... :)
10
+ RSmaz is a pure-Ruby port of the Smaz short string compression
11
+ algorithm by Salvatore Sanfilippo and released as a C library at:
12
+ http://github.com/antirez/smaz/tree/master
13
+
14
+ I've done some initial cleanup of a pure Ruby->C port, but this
15
+ is not yet complete. It does pass the specs, however! Feel free
16
+ to clean it up as it's a bit memory inefficient right now... :)
17
17
 
18
18
  == REQUIREMENTS:
19
19
 
20
- * RSpec (if you want to run the specs)
21
- * Some strings to compress
22
- * A sense of humor
20
+ * MiniTest (in the Ruby 1.9 stdlib or `gem install minitest` on Ruby 1.8)
21
+
22
+ == INSTALLATION:
23
+
24
+ gem install rsmaz
23
25
 
24
26
  == USAGE:
25
27
 
@@ -27,9 +29,19 @@
27
29
  r = RSmaz.compress("whatever")
28
30
  puts RSmaz.decompress(r)
29
31
 
32
+ === Ruby 1.9 and encodings
33
+
34
+ RSmaz.compress always returns a string with the binary encoding. The
35
+ input can be any encoding, it will internally force it to binary
36
+ and compress byte-by-byte.
37
+
38
+ RSmaz.decompress also always returns a string with the binary encoding.
39
+ You must manually force the encoding back to the right one because
40
+ RSmaz does not store information about the original encoding.
41
+
30
42
  == RSMAZ LICENSE:
31
43
 
32
- Copyright (c) 2009 Peter Cooper, Salvatore Sanfilippo
44
+ Copyright (c) 2009-2011 Peter Cooper, Salvatore Sanfilippo, Hongli Lai
33
45
 
34
46
  Permission is hereby granted, free of charge, to any person obtaining
35
47
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,28 +1,9 @@
1
- %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
- require File.dirname(__FILE__) + '/lib/rsmaz'
1
+ %w[rubygems rake rake/testtask].each { |f| require f }
3
2
 
4
- # Generate all the Rake tasks
5
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
- $hoe = Hoe.new('rsmaz', RSmaz::VERSION) do |p|
7
- p.developer('Peter Cooper', 'pcooper@petercooper.co.uk')
8
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
- p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
- p.rubyforge_name = p.name # TODO this is default value
11
- # p.extra_deps = [
12
- # ['activesupport','>= 2.0.2'],
13
- # ]
14
- p.extra_dev_deps = [
15
- ['newgem', ">= #{::Newgem::VERSION}"]
16
- ]
17
-
18
- p.clean_globs |= %w[**/.DS_Store tmp *.log]
19
- path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
20
- p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
- p.rsync_args = '-av --delete --ignore-errors'
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'lib' << 'test'
5
+ test.pattern = 'test/**/test_*.rb'
6
+ test.verbose = true
22
7
  end
23
8
 
24
- require 'newgem/tasks' # load /tasks/*.rake
25
- Dir['tasks/**/*.rake'].each { |t| load t }
26
-
27
- # TODO - want other tests/tasks run by default? Add them to the list
28
- # task :default => [:spec, :features]
9
+ task :default => :test
@@ -1,3 +1,4 @@
1
+ # encoding: binary
1
2
  $:.unshift(File.dirname(__FILE__)) unless
2
3
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
4
 
@@ -86,11 +87,12 @@ module RSmaz
86
87
  " we", "ly", "ee", " n", "id", " cl", "ac", "il", "</", "rt", " wi", "div",
87
88
  "e, ", " it", "whi", " ma", "ge", "x", "e c", "men", ".com"]
88
89
 
89
- # Compress a string to Smaz encoding
90
+ # Compress a string to Smaz encoding. On Ruby 1.9, the returned string
91
+ # has the binary encoding.
90
92
  def self.compress(input)
91
93
  verb = ""
92
94
  out = ""
93
- input = input.dup
95
+ input = force_binary(input.dup)
94
96
 
95
97
  # This algorithm has been ported to Ruby from C and only
96
98
  # slightly Rubyized.. still a lonnnng way to go. Wanna give it a crack?
@@ -159,10 +161,13 @@ module RSmaz
159
161
  out
160
162
  end
161
163
 
162
- # Decompress a Smaz encoded string back to normal plain text
164
+ # Decompress a Smaz encoded string back to normal plain text.
165
+ # On Ruby 1.9, the returned string has the binary encoding. You
166
+ # must manually force the encoding back to the right one because
167
+ # RSmaz does not store information about the original encoding.
163
168
  def self.decompress(input)
164
169
  out = ""
165
- s = StringScanner.new(input)
170
+ s = StringScanner.new(dup_and_force_binary(input))
166
171
  until s.eos?
167
172
  bv = s.get_byte.ord
168
173
  if (bv == 254)
@@ -179,4 +184,23 @@ module RSmaz
179
184
 
180
185
  out
181
186
  end
187
+
188
+ private
189
+ if ''.respond_to?(:encoding)
190
+ def self.force_binary(str)
191
+ str.force_encoding('binary')
192
+ end
193
+
194
+ def self.dup_and_force_binary(str)
195
+ str.dup.force_encoding('binary')
196
+ end
197
+ else
198
+ def self.force_binary(str)
199
+ str
200
+ end
201
+
202
+ def self.dup_and_force_binary(str)
203
+ str
204
+ end
205
+ end
182
206
  end
@@ -1,9 +1,9 @@
1
1
  begin
2
- require 'spec'
2
+ require 'minitest/spec'
3
3
  rescue LoadError
4
4
  require 'rubygems'
5
- gem 'rspec'
6
- require 'spec'
5
+ gem 'minitest'
6
+ require 'minitest/spec'
7
7
  end
8
8
 
9
9
  $:.unshift(File.dirname(__FILE__) + '/../lib')
@@ -11,4 +11,6 @@ require 'rsmaz'
11
11
 
12
12
  def memory_usage
13
13
  `ps -Orss #{Process.pid} | tail -1`.scan(/\d+/)[1].to_i rescue 0
14
- end
14
+ end
15
+
16
+ MiniTest::Unit.autorun
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
2
+
3
+ describe RSmaz do
4
+
5
+ #before(:each) do
6
+ # # Do some memory leak checking
7
+ # puts "\nMemory used: #{memory_usage}K"
8
+ #end
9
+ #
10
+ #after(:each) do
11
+ # puts "\nMemory used: #{memory_usage}K"
12
+ #end
13
+
14
+ it "should compress 'the' to one byte" do
15
+ RSmaz.compress("the").length.must_equal 1
16
+ end
17
+
18
+ it "should compress 'thex' to two bytes" do
19
+ RSmaz.compress("thex").length.must_equal 2
20
+ end
21
+
22
+ it "should compress and decompress strings back to the same string" do
23
+ [
24
+ "This is a test.",
25
+ "This is a test",
26
+ "this is a test",
27
+ "Let's try a SlIgHtLy Funkie938R str1ng!?!?x",
28
+ "What about a long one?" * 100
29
+ ].each { |str| RSmaz.decompress(RSmaz.compress(str)).must_equal str }
30
+ end
31
+
32
+ it "should properly decode a reference compression (so the internal coding doesn't change)" do
33
+ RSmaz.decompress("\020\230`A\376o\f\026\030").must_equal "hello world"
34
+ end
35
+
36
+ it "should compress to the same extent as the reference smaz implementation" do
37
+ RSmaz.compress("foobar").length.must_equal 4
38
+ RSmaz.compress("Nel mezzo del cammin di nostra vita, mi ritrovai in una selva oscura").length.must_equal 46
39
+ end
40
+
41
+ it "should compress and decompress lots of random strings without issues" do
42
+ 100.times do
43
+ str = (1..100).map { |a| (rand(26)+97).chr }.join
44
+ RSmaz.decompress(RSmaz.compress(str)).length.must_equal str.length
45
+ end
46
+ end
47
+
48
+ it "should compress and decompress lots of random strings without issues (again)" do
49
+ 100.times do
50
+ str = (1..100).map { |a| (rand(26)+97).chr }.join
51
+ RSmaz.decompress(RSmaz.compress(str)).length.must_equal str.length
52
+ end
53
+ end
54
+
55
+ if ''.respond_to?(:encoding)
56
+ # U+2603 = Unicode snowman
57
+
58
+ it "should be able to compress strings with arbitrary encodings" do
59
+ RSmaz.decompress(RSmaz.compress("\u2603")).force_encoding('utf-8').must_equal "\u2603"
60
+ end
61
+
62
+ it "should return binary strings upon compressing" do
63
+ RSmaz.compress("\u2603").encoding.must_equal Encoding.find('binary')
64
+ end
65
+
66
+ it "should return binary strings upon decompressing" do
67
+ RSmaz.decompress(RSmaz.compress("\u2603")).encoding.must_equal Encoding.find('binary')
68
+ end
69
+ end
70
+ end
71
+
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsmaz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ prerelease:
5
+ version: 0.0.4
5
6
  platform: ruby
6
7
  authors:
7
8
  - Peter Cooper
@@ -9,83 +10,64 @@ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-04-02 00:00:00 +01:00
13
+ date: 2011-03-26 00:00:00 +00:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
- name: newgem
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
17
+ name: minitest
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
20
21
  requirements:
21
22
  - - ">="
22
23
  - !ruby/object:Gem::Version
23
- version: 1.3.0
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: hoe
24
+ version: "0"
27
25
  type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.8.0
34
- version:
35
- description: "Short String Compression for Ruby. RSmaz is a pure-Ruby port of the Smaz short string compression algorithm by Salvatore Sanfilippo and released as a C library at: http://github.com/antirez/smaz/tree/master I've done some initial cleanup of a pure Ruby->C port, but this is not yet complete. It does pass the specs, however! Feel free to clean it up as it's a bit memory inefficient right now... :)"
26
+ version_requirements: *id001
27
+ description: "Short String Compression for Ruby. RSmaz is a pure-Ruby port of the Smaz short string compression algorithm by Salvatore Sanfilippo and released as a C library at: http://github.com/antirez/smaz/tree/master I've done some initial cleanup of a pure Ruby->C port, but this is not yet complete. It does pass the specs, however! Feel free to clean it up as it's a bit memory inefficient right now... :)"
36
28
  email:
37
- - pcooper@petercooper.co.uk
29
+ - git@peterc.org
38
30
  executables: []
39
31
 
40
32
  extensions: []
41
33
 
42
34
  extra_rdoc_files:
43
- - History.txt
44
- - Manifest.txt
45
- - PostInstall.txt
35
+ - HISTORY
46
36
  - README.rdoc
47
37
  files:
48
- - History.txt
49
- - Manifest.txt
50
- - PostInstall.txt
51
- - README.rdoc
38
+ - HISTORY
52
39
  - Rakefile
40
+ - README.rdoc
41
+ - test/test_helper.rb
42
+ - test/test_rsmaz.rb
53
43
  - lib/rsmaz.rb
54
- - script/console
55
- - script/destroy
56
- - script/generate
57
- - spec/rsmaz_spec.rb
58
- - spec/spec.opts
59
- - spec/spec_helper.rb
60
- - tasks/rspec.rake
61
44
  has_rdoc: true
62
- homepage: http://github.com/peterc/rsmaz/tree/master
45
+ homepage: http://github.com/peterc/rsmaz
63
46
  licenses: []
64
47
 
65
- post_install_message: PostInstall.txt
66
- rdoc_options:
67
- - --main
68
- - README.rdoc
48
+ post_install_message:
49
+ rdoc_options: []
50
+
69
51
  require_paths:
70
52
  - lib
71
53
  required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
72
55
  requirements:
73
56
  - - ">="
74
57
  - !ruby/object:Gem::Version
75
58
  version: "0"
76
- version:
77
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
78
61
  requirements:
79
62
  - - ">="
80
63
  - !ruby/object:Gem::Version
81
64
  version: "0"
82
- version:
83
65
  requirements: []
84
66
 
85
- rubyforge_project: rsmaz
86
- rubygems_version: 1.3.5
67
+ rubyforge_project:
68
+ rubygems_version: 1.6.2
87
69
  signing_key:
88
- specification_version: 2
70
+ specification_version: 3
89
71
  summary: Short String Compression for Ruby
90
72
  test_files: []
91
73
 
@@ -1,13 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- PostInstall.txt
4
- README.rdoc
5
- Rakefile
6
- lib/rsmaz.rb
7
- script/console
8
- script/destroy
9
- script/generate
10
- spec/rsmaz_spec.rb
11
- spec/spec.opts
12
- spec/spec_helper.rb
13
- tasks/rspec.rake
@@ -1,6 +0,0 @@
1
- Code example:
2
-
3
- require 'rsmaz'
4
- RSmaz.decompress(RSmaz.compress("this is a test"))
5
-
6
- For more information on smaz in general, see http://github.com/antirez/smaz/tree/master
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # File: script/console
3
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
-
5
- libs = " -r irb/completion"
6
- # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
- # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
- libs << " -r #{File.dirname(__FILE__) + '/../lib/rsmaz.rb'}"
9
- puts "Loading rsmaz gem"
10
- exec "#{irb} #{libs} --simple-prompt"
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/destroy'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/generate'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Generate.new.run(ARGV)
@@ -1,56 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- describe RSmaz do
4
-
5
- before(:each) do
6
- # Do some memory leak checking
7
- puts "\nMemory used: #{memory_usage}K"
8
- end
9
-
10
- after(:each) do
11
- puts "\nMemory used: #{memory_usage}K"
12
- end
13
-
14
- it "should compress 'the' to one byte" do
15
- RSmaz.compress("the").length.should == 1
16
- end
17
-
18
- it "should compress 'thex' to two bytes" do
19
- RSmaz.compress("thex").length.should == 2
20
- end
21
-
22
- it "should compress and decompress strings back to the same string" do
23
- [
24
- "This is a test.",
25
- "This is a test",
26
- "this is a test",
27
- "Let's try a SlIgHtLy Funkie938R str1ng!?!?x",
28
- "What about a long one?" * 100
29
- ].each { |str| RSmaz.decompress(RSmaz.compress(str)).should == str }
30
- end
31
-
32
- it "should properly decode a reference compression (so the internal coding doesn't change)" do
33
- RSmaz.decompress("\020\230`A\376o\f\026\030").should == "hello world"
34
- end
35
-
36
- it "should compress to the same extent as the reference smaz implementation" do
37
- RSmaz.compress("foobar").length.should == 4
38
- RSmaz.compress("Nel mezzo del cammin di nostra vita, mi ritrovai in una selva oscura").length.should == 46
39
- end
40
-
41
- it "should compress and decompress lots of random strings without issues" do
42
- 100.times do
43
- str = (1..100).map { |a| (rand(26)+97).chr }.join
44
- RSmaz.decompress(RSmaz.compress(str)).length.should == str.length
45
- end
46
- end
47
-
48
- it "should compress and decompress lots of random strings without issues (again)" do
49
- 100.times do
50
- str = (1..100).map { |a| (rand(26)+97).chr }.join
51
- RSmaz.decompress(RSmaz.compress(str)).length.should == str.length
52
- end
53
- end
54
-
55
-
56
- end
@@ -1 +0,0 @@
1
- --colour
@@ -1,21 +0,0 @@
1
- begin
2
- require 'spec'
3
- rescue LoadError
4
- require 'rubygems'
5
- require 'spec'
6
- end
7
- begin
8
- require 'spec/rake/spectask'
9
- rescue LoadError
10
- puts <<-EOS
11
- To use rspec for testing you must install rspec gem:
12
- gem install rspec
13
- EOS
14
- exit(0)
15
- end
16
-
17
- desc "Run the specs under spec/models"
18
- Spec::Rake::SpecTask.new do |t|
19
- t.spec_opts = ['--options', "spec/spec.opts"]
20
- t.spec_files = FileList['spec/**/*_spec.rb']
21
- end