Ascii85 0.9.0 → 1.1.0
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.
- checksums.yaml +7 -0
- data/.travis.yml +30 -0
- data/Ascii85.gemspec +25 -0
- data/Gemfile +4 -0
- data/History.txt +27 -0
- data/LICENSE +19 -0
- data/README.md +69 -0
- data/Rakefile +8 -39
- data/bin/ascii85 +80 -0
- data/lib/Ascii85/version.rb +5 -0
- data/lib/ascii85.rb +77 -59
- data/spec/lib/ascii85_spec.rb +195 -0
- metadata +83 -73
- data.tar.gz.sig +0 -0
- data/Manifest.txt +0 -6
- data/README.txt +0 -59
- data/spec/ascii85_spec.rb +0 -152
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dcb6cc7ca3f3ca02c235e5a0d5b908396524e265c9adaaf56c50bc62117c5ee7
|
4
|
+
data.tar.gz: c005e9a67ecc1def46d040f06e91cb7984d0cfd43d9729638d60b2fe19d2ab8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c6fef31cebe36d41eee64ff857e87007b176b262fc4c667666f6360714b9d15274afb192572cf5bba31953f13ecde7c1b1ea60697ebf83a43dc80b35f64d94dd
|
7
|
+
data.tar.gz: 2bd0e1367f729cb42d2163e5eeeba540e243138a23cfeb6bf9e2d93d49c80dc12227d65b60bd1db2f6272ab8c9bac19d0aaac37a5e9d48e14dd50d45abb8a749
|
data/.travis.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9
|
4
|
+
- 2.0
|
5
|
+
- 2.1
|
6
|
+
- 2.2
|
7
|
+
- 2.3
|
8
|
+
- 2.4
|
9
|
+
- 2.5
|
10
|
+
- 2.6
|
11
|
+
- 2.7
|
12
|
+
- ruby-head
|
13
|
+
- jruby
|
14
|
+
- truffleruby
|
15
|
+
env:
|
16
|
+
- RUBYOPT="--enable-frozen-string-literal"
|
17
|
+
- RUBYOPT=""
|
18
|
+
matrix:
|
19
|
+
exclude:
|
20
|
+
- rvm: 1.9
|
21
|
+
env: RUBYOPT="--enable-frozen-string-literal"
|
22
|
+
- rvm: 2.0
|
23
|
+
env: RUBYOPT="--enable-frozen-string-literal"
|
24
|
+
- rvm: 2.1
|
25
|
+
env: RUBYOPT="--enable-frozen-string-literal"
|
26
|
+
- rvm: 2.2
|
27
|
+
env: RUBYOPT="--enable-frozen-string-literal"
|
28
|
+
# bundler did not support this back then
|
29
|
+
- rvm: 2.3
|
30
|
+
env: RUBYOPT="--enable-frozen-string-literal"
|
data/Ascii85.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "Ascii85/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "Ascii85"
|
7
|
+
s.version = Ascii85::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.author = "Johannes Holzfuß"
|
10
|
+
s.email = "johannes@holzfuss.name"
|
11
|
+
s.license = 'MIT'
|
12
|
+
s.homepage = "https://github.com/DataWraith/ascii85gem/"
|
13
|
+
s.summary = %q{Ascii85 encoder/decoder}
|
14
|
+
s.description = %q{Ascii85 provides methods to encode/decode Adobe's binary-to-text encoding of the same name.}
|
15
|
+
|
16
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
17
|
+
s.add_development_dependency "minitest",">= 2.6.0"
|
18
|
+
s.add_development_dependency "rake", ">= 0.9.2"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n") - ['.gitignore']
|
21
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
25
|
+
end
|
data/Gemfile
ADDED
data/History.txt
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
=== 1.1.0 / 2020-11-11
|
2
|
+
|
3
|
+
* Make use of frozen_string_literal
|
4
|
+
* Update tests to use newer minitest syntax
|
5
|
+
|
6
|
+
=== 1.0.3 / 2018-01-25
|
7
|
+
|
8
|
+
* Updated the gem's metadata
|
9
|
+
|
10
|
+
=== 1.0.2 / 2012-09-16
|
11
|
+
|
12
|
+
* Changed test runner from RSpec to MiniSpec
|
13
|
+
* Support for rubygems-test
|
14
|
+
* Minor changes to make packaging easier
|
15
|
+
|
16
|
+
=== 1.0.1 / 2011-05-05
|
17
|
+
|
18
|
+
* Removed hoe dependency in favor of bundler
|
19
|
+
* Minor corrections in the documentation
|
20
|
+
|
21
|
+
=== 1.0.0 / 2009-12-25
|
22
|
+
|
23
|
+
* 2 major enhancements
|
24
|
+
|
25
|
+
* Ruby 1.9 compatibility
|
26
|
+
* Added command-line en- and decoder
|
27
|
+
|
1
28
|
=== 0.9.0 / 2009-02-17
|
2
29
|
|
3
30
|
* 1 major enhancement
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Johannes Holzfuß
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
**Status**: This project is in maintenance mode. I will not develop new features, but I will address Issues and Pull Requests.
|
2
|
+
|
3
|
+
# Ascii85
|
4
|
+
|
5
|
+
[](https://travis-ci.org/DataWraith/ascii85gem)
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
Ascii85 is a simple gem that provides methods for encoding/decoding Adobe's
|
10
|
+
binary-to-text encoding of the same name.
|
11
|
+
|
12
|
+
See http://www.adobe.com/products/postscript/pdfs/PLRM.pdf page 131 and
|
13
|
+
http://en.wikipedia.org/wiki/Ascii85 for more information about the format.
|
14
|
+
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
`sudo gem install Ascii85`
|
19
|
+
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```
|
24
|
+
require 'rubygems'
|
25
|
+
require 'ascii85'
|
26
|
+
|
27
|
+
Ascii85.encode("Ruby")
|
28
|
+
=> "<~;KZGo~>"
|
29
|
+
|
30
|
+
Ascii85.decode("<~;KZGo~>")
|
31
|
+
=> "Ruby"
|
32
|
+
```
|
33
|
+
|
34
|
+
In addition, Ascii85.encode can take a second parameter that specifies the
|
35
|
+
length of the returned lines. The default is 80; use `false` for unlimited.
|
36
|
+
|
37
|
+
Ascii85.decode expects the input to be enclosed in <~ and ~> — it
|
38
|
+
ignores everything outside of these. The output of Ascii85.decode
|
39
|
+
will have the ASCII-8BIT encoding, so in Ruby 1.9 you may have to use
|
40
|
+
<tt>String#force_encoding</tt> to correct the encoding.
|
41
|
+
|
42
|
+
|
43
|
+
## Command-line utility
|
44
|
+
|
45
|
+
This gem includes `ascii85`, a command-line utility modeled after `base64` from
|
46
|
+
the GNU coreutils. It can be used to encode/decode Ascii85 directly from the
|
47
|
+
command-line:
|
48
|
+
|
49
|
+
```
|
50
|
+
Usage: ascii85 [OPTIONS] [FILE]
|
51
|
+
Encodes or decodes FILE or STDIN using Ascii85 and writes to STDOUT.
|
52
|
+
-w, --wrap COLUMN Wrap lines at COLUMN. Default is 80, use 0 for no wrapping
|
53
|
+
-d, --decode Decode the input
|
54
|
+
-h, --help Display this help and exit
|
55
|
+
--version Output version information
|
56
|
+
```
|
57
|
+
|
58
|
+
|
59
|
+
## Contributors
|
60
|
+
|
61
|
+
Thank you for your contribution!
|
62
|
+
|
63
|
+
* [@aliismayilov](https://github.com/aliismayilov) contributed frozen String handling
|
64
|
+
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
Ascii85 is distributed under the MIT License. See the accompanying LICENSE file
|
69
|
+
for details.
|
data/Rakefile
CHANGED
@@ -1,43 +1,12 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
1
3
|
|
2
|
-
require '
|
4
|
+
require 'rake/testtask'
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
require 'rake/clean'
|
7
|
-
require 'rake/rdoctask'
|
8
|
-
require 'spec/rake/spectask'
|
9
|
-
|
10
|
-
require 'lib/ascii85.rb'
|
11
|
-
|
12
|
-
|
13
|
-
# rspec
|
14
|
-
|
15
|
-
desc "Run specs"
|
16
|
-
Spec::Rake::SpecTask.new do |t|
|
17
|
-
t.spec_opts = ["--color"]
|
18
|
-
end
|
19
|
-
|
20
|
-
desc "Show specdoc"
|
21
|
-
Spec::Rake::SpecTask.new('specdoc') do |t|
|
22
|
-
t.spec_opts = ["--color", "--format=specdoc"]
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
# Hoe
|
27
|
-
|
28
|
-
Hoe.new('Ascii85', Ascii85::VERSION) do |p|
|
29
|
-
p.author = "Johannes Holzfuß"
|
30
|
-
p.email = "Drangon@gmx.de"
|
31
|
-
p.summary = "Ascii85 encoder/decoder"
|
32
|
-
|
33
|
-
p.description = "Ascii85 provides methods to encode/decode Adobe's binary-to-text encoding of the same name."
|
34
|
-
|
35
|
-
p.remote_rdoc_dir = ''
|
36
|
-
|
37
|
-
p.testlib = "spec"
|
38
|
-
p.test_globs = "spec/ascii85_spec.rb"
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
39
8
|
end
|
40
9
|
|
41
|
-
|
42
|
-
|
43
|
-
task :default => :
|
10
|
+
task :specs => :test
|
11
|
+
task :tests => :test
|
12
|
+
task :default => :test
|
data/bin/ascii85
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
#
|
5
|
+
# A simple command-line tool to de- and encode Ascii85, modeled after `base64`
|
6
|
+
# from the GNU Coreutils.
|
7
|
+
#
|
8
|
+
|
9
|
+
|
10
|
+
require "optparse"
|
11
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'ascii85')
|
12
|
+
|
13
|
+
@options = {
|
14
|
+
:wrap => 80,
|
15
|
+
:decode => false
|
16
|
+
}
|
17
|
+
|
18
|
+
ARGV.options do |opts|
|
19
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] [FILE]\n" +
|
20
|
+
"Encodes or decodes FILE or STDIN using Ascii85 and writes to STDOUT."
|
21
|
+
|
22
|
+
|
23
|
+
opts.on( "-w", "--wrap COLUMN", Integer,
|
24
|
+
"Wrap lines at COLUMN. Default is 80, use 0 for no wrapping") do |opt|
|
25
|
+
|
26
|
+
@options[:wrap] = opt.abs
|
27
|
+
@options[:wrap] = false if opt.zero?
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on( "-d", "--decode", "Decode the input") do
|
31
|
+
@options[:decode] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on( "-h", "--help", "Display this help and exit") do
|
35
|
+
puts opts
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on( "--version", "Output version information") do |opt|
|
40
|
+
puts "Ascii85 v#{Ascii85::VERSION},\nwritten by Johannes Holzfuß"
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
|
44
|
+
remaining_args = opts.parse!
|
45
|
+
|
46
|
+
case remaining_args.size
|
47
|
+
when 0
|
48
|
+
@options[:file] = '-'
|
49
|
+
when 1
|
50
|
+
@options[:file] = remaining_args.first
|
51
|
+
else
|
52
|
+
abort "Superfluous operand(s): \"#{remaining_args.join('", "')}\""
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if @options[:file] == '-'
|
57
|
+
@input = $stdin.binmode.read
|
58
|
+
else
|
59
|
+
unless File.exists?(@options[:file])
|
60
|
+
abort "File not found: \"#{@options[:file]}\""
|
61
|
+
end
|
62
|
+
|
63
|
+
unless File.readable_real?(@options[:file])
|
64
|
+
abort "File is not readable: \"#{@options[:file]}\""
|
65
|
+
end
|
66
|
+
|
67
|
+
File.open(@options[:file], 'rb') do |f|
|
68
|
+
@input = f.read
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
if @options[:decode]
|
73
|
+
begin
|
74
|
+
print Ascii85.decode(@input)
|
75
|
+
rescue Ascii85::DecodingError => error
|
76
|
+
abort "Decoding Error: #{error.message.to_s}"
|
77
|
+
end
|
78
|
+
else
|
79
|
+
print Ascii85.encode(@input, @options[:wrap])
|
80
|
+
end
|
data/lib/ascii85.rb
CHANGED
@@ -1,57 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
|
1
5
|
#
|
2
|
-
# Ascii85 is an implementation of Adobe's binary-to-text encoding of the
|
3
|
-
# name in pure Ruby.
|
6
|
+
# Ascii85 is an implementation of Adobe's binary-to-text encoding of the
|
7
|
+
# same name in pure Ruby.
|
4
8
|
#
|
5
|
-
# See http://www.adobe.com/products/postscript/pdfs/PLRM.pdf page 131
|
6
|
-
# http://en.wikipedia.org/wiki/Ascii85 for more information about
|
9
|
+
# See http://www.adobe.com/products/postscript/pdfs/PLRM.pdf page 131
|
10
|
+
# and http://en.wikipedia.org/wiki/Ascii85 for more information about
|
11
|
+
# the format.
|
7
12
|
#
|
8
|
-
# Author:: Johannes Holzfuß (
|
9
|
-
# License:: Distributed under the MIT License (see
|
13
|
+
# Author:: Johannes Holzfuß (johannes@holzfuss.name)
|
14
|
+
# License:: Distributed under the MIT License (see LICENSE file)
|
10
15
|
#
|
11
16
|
|
12
17
|
|
13
18
|
module Ascii85
|
14
|
-
# The gem version number
|
15
|
-
VERSION = '0.9.0' # :nodoc:
|
16
|
-
|
17
19
|
#
|
18
|
-
# Encodes the given String as Ascii85.
|
20
|
+
# Encodes the bytes of the given String as Ascii85.
|
19
21
|
#
|
20
|
-
# If +wrap_lines+ evaluates to +false+, the output will be returned as
|
21
|
-
# single long line. Otherwise #encode formats the output into lines
|
22
|
-
# length +wrap_lines+ (minimum is 2).
|
22
|
+
# If +wrap_lines+ evaluates to +false+, the output will be returned as
|
23
|
+
# a single long line. Otherwise #encode formats the output into lines
|
24
|
+
# of length +wrap_lines+ (minimum is 2).
|
23
25
|
#
|
24
|
-
# Ascii85
|
26
|
+
# Ascii85.encode("Ruby")
|
25
27
|
# => <~;KZGo~>
|
26
28
|
#
|
27
|
-
# Ascii85
|
29
|
+
# Ascii85.encode("Supercalifragilisticexpialidocious", 15)
|
28
30
|
# => <~;g!%jEarNoBkD
|
29
31
|
# BoB5)0rF*),+AU&
|
30
32
|
# 0.@;KXgDe!L"F`R
|
31
33
|
# ~>
|
32
34
|
#
|
33
|
-
# Ascii85
|
35
|
+
# Ascii85.encode("Supercalifragilisticexpialidocious", false)
|
34
36
|
# => <~;g!%jEarNoBkDBoB5)0rF*),+AU&0.@;KXgDe!L"F`R~>
|
35
37
|
#
|
36
38
|
#
|
37
39
|
def self.encode(str, wrap_lines = 80)
|
40
|
+
to_encode = str.to_s
|
41
|
+
return '' if to_encode.empty?
|
38
42
|
|
39
|
-
|
43
|
+
# Deal with multi-byte encodings
|
44
|
+
if to_encode.respond_to?(:bytesize)
|
45
|
+
input_size = to_encode.bytesize
|
46
|
+
else
|
47
|
+
input_size = to_encode.size
|
48
|
+
end
|
40
49
|
|
41
50
|
# Compute number of \0s to pad the message with (0..3)
|
42
|
-
padding_length = (-
|
51
|
+
padding_length = (-input_size) % 4
|
43
52
|
|
44
53
|
# Extract big-endian integers
|
45
|
-
tuples = (
|
54
|
+
tuples = (to_encode + ("\0" * padding_length)).unpack('N*')
|
46
55
|
|
47
56
|
# Encode
|
48
57
|
tuples.map! do |tuple|
|
49
58
|
if tuple == 0
|
50
59
|
'z'
|
51
60
|
else
|
52
|
-
tmp =
|
61
|
+
tmp = String.new
|
53
62
|
5.times do
|
54
|
-
tmp
|
63
|
+
tmp << ((tuple % 85) + 33).chr
|
55
64
|
tuple /= 85
|
56
65
|
end
|
57
66
|
tmp.reverse
|
@@ -66,28 +75,26 @@ module Ascii85
|
|
66
75
|
# Cut off the padding
|
67
76
|
tuples[-1] = tuples[-1][0..(4 - padding_length)]
|
68
77
|
|
69
|
-
#
|
70
|
-
result = '<~' + tuples.join
|
71
|
-
|
72
|
-
# If we don't need to wrap the lines to a certain length, add ~> and return
|
78
|
+
# If we don't need to wrap the lines, add delimiters and return
|
73
79
|
if (!wrap_lines)
|
74
|
-
return
|
80
|
+
return '<~' + tuples.join + '~>'
|
75
81
|
end
|
76
82
|
|
77
83
|
# Otherwise we wrap the lines
|
78
|
-
|
79
84
|
line_length = [2, wrap_lines.to_i].max
|
80
85
|
|
81
86
|
wrapped = []
|
82
|
-
|
83
|
-
|
87
|
+
to_wrap = '<~' + tuples.join
|
88
|
+
|
89
|
+
0.step(to_wrap.length, line_length) do |index|
|
90
|
+
wrapped << to_wrap.slice(index, line_length)
|
84
91
|
end
|
85
92
|
|
86
|
-
# Add end-marker
|
93
|
+
# Add end-marker – on a new line if necessary
|
87
94
|
if (wrapped.last.length + 2) > line_length
|
88
95
|
wrapped << '~>'
|
89
96
|
else
|
90
|
-
wrapped[-1]
|
97
|
+
wrapped[-1] << '~>'
|
91
98
|
end
|
92
99
|
|
93
100
|
return wrapped.join("\n")
|
@@ -96,43 +103,55 @@ module Ascii85
|
|
96
103
|
#
|
97
104
|
# Searches through +str+ and decodes the _first_ Ascii85-String found.
|
98
105
|
#
|
99
|
-
# #decode expects an Ascii85-encoded String enclosed in <~ and
|
100
|
-
# ignore all characters outside these markers.
|
106
|
+
# #decode expects an Ascii85-encoded String enclosed in <~ and ~> — it will
|
107
|
+
# ignore all characters outside these markers. The returned strings are always
|
108
|
+
# encoded as ASCII-8BIT.
|
101
109
|
#
|
102
|
-
# Ascii85
|
110
|
+
# Ascii85.decode("<~;KZGo~>")
|
103
111
|
# => "Ruby"
|
104
112
|
#
|
105
|
-
# Ascii85
|
113
|
+
# Ascii85.decode("Foo<~;KZGo~>Bar<~;KZGo~>Baz")
|
106
114
|
# => "Ruby"
|
107
115
|
#
|
108
|
-
# Ascii85
|
116
|
+
# Ascii85.decode("No markers")
|
109
117
|
# => ""
|
110
118
|
#
|
111
119
|
# #decode will raise Ascii85::DecodingError when malformed input is
|
112
120
|
# encountered.
|
113
121
|
#
|
114
122
|
def self.decode(str)
|
123
|
+
input = str.to_s
|
124
|
+
|
125
|
+
opening_delim = '<~'
|
126
|
+
closing_delim = '~>'
|
127
|
+
|
128
|
+
# Make sure the delimiter strings have the correct encoding.
|
129
|
+
#
|
130
|
+
# Although I don't think it likely, this may raise encoding
|
131
|
+
# errors if an especially exotic input encoding is introduced.
|
132
|
+
# As of Ruby 1.9.2 all non-dummy encodings work fine though.
|
133
|
+
#
|
134
|
+
if opening_delim.respond_to?(:encode)
|
135
|
+
opening_delim = opening_delim.encode(input.encoding)
|
136
|
+
closing_delim = closing_delim.encode(input.encoding)
|
137
|
+
end
|
115
138
|
|
116
|
-
#
|
117
|
-
|
118
|
-
|
119
|
-
return ''
|
120
|
-
|
121
|
-
# Remove the delimiters
|
122
|
-
input = input.to_s[2..-3]
|
139
|
+
# Get the positions of the opening/closing delimiters. If there is
|
140
|
+
# no pair of opening/closing delimiters, return the empty string.
|
141
|
+
(start_pos = input.index(opening_delim)) or return ''
|
142
|
+
(end_pos = input.index(closing_delim, start_pos + 2)) or return ''
|
123
143
|
|
124
|
-
|
144
|
+
# Get the string inside the delimiter-pair
|
145
|
+
input = input[(start_pos + 2)...end_pos]
|
125
146
|
|
126
147
|
# Decode
|
148
|
+
word = 0
|
149
|
+
count = 0
|
127
150
|
result = []
|
128
151
|
|
129
|
-
count = 0
|
130
|
-
word = 0
|
131
|
-
|
132
152
|
input.each_byte do |c|
|
133
|
-
|
134
153
|
case c.chr
|
135
|
-
when
|
154
|
+
when " ", "\t", "\r", "\n", "\f", "\0"
|
136
155
|
# Ignore whitespace
|
137
156
|
next
|
138
157
|
|
@@ -146,18 +165,19 @@ module Ascii85
|
|
146
165
|
|
147
166
|
when '!'..'u'
|
148
167
|
# Decode 5 characters into a 4-byte word
|
149
|
-
word
|
168
|
+
word += (c - 33) * 85**(4 - count)
|
150
169
|
count += 1
|
151
170
|
|
152
171
|
if count == 5
|
153
172
|
|
154
|
-
if word
|
173
|
+
if word > 0xffffffff
|
155
174
|
raise(Ascii85::DecodingError,
|
156
175
|
"Invalid Ascii85 5-tuple (#{word} >= 2**32)")
|
157
176
|
end
|
158
177
|
|
159
178
|
result << word
|
160
|
-
|
179
|
+
|
180
|
+
word = 0
|
161
181
|
count = 0
|
162
182
|
end
|
163
183
|
|
@@ -165,7 +185,6 @@ module Ascii85
|
|
165
185
|
raise(Ascii85::DecodingError,
|
166
186
|
"Illegal character inside Ascii85: #{c.chr.dump}")
|
167
187
|
end
|
168
|
-
|
169
188
|
end
|
170
189
|
|
171
190
|
# Convert result into a String
|
@@ -180,18 +199,18 @@ module Ascii85
|
|
180
199
|
end
|
181
200
|
|
182
201
|
count -= 1
|
183
|
-
word
|
202
|
+
word += 85**(4 - count)
|
184
203
|
|
185
|
-
result
|
186
|
-
result
|
187
|
-
result
|
204
|
+
result << ((word >> 24) & 255).chr if count >= 1
|
205
|
+
result << ((word >> 16) & 255).chr if count >= 2
|
206
|
+
result << ((word >> 8) & 255).chr if count == 3
|
188
207
|
end
|
189
208
|
|
190
209
|
return result
|
191
210
|
end
|
192
211
|
|
193
212
|
#
|
194
|
-
# This error is raised when Ascii85
|
213
|
+
# This error is raised when Ascii85.decode encounters one of the following
|
195
214
|
# problems in the input:
|
196
215
|
#
|
197
216
|
# * An invalid character. Valid characters are '!'..'u' and 'z'.
|
@@ -201,5 +220,4 @@ module Ascii85
|
|
201
220
|
# at least two characters.
|
202
221
|
#
|
203
222
|
class DecodingError < StandardError; end
|
204
|
-
|
205
223
|
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
# Require implementation
|
7
|
+
require File.expand_path('../../../lib/ascii85', __FILE__)
|
8
|
+
|
9
|
+
describe Ascii85 do
|
10
|
+
UNSUPPORTED_MSG = "This version of Ruby does not support encodings"
|
11
|
+
|
12
|
+
TEST_CASES = {
|
13
|
+
"" => "",
|
14
|
+
" " => "<~+9~>",
|
15
|
+
|
16
|
+
"\0" * 1 => "<~!!~>",
|
17
|
+
"\0" * 2 => "<~!!!~>",
|
18
|
+
"\0" * 3 => "<~!!!!~>",
|
19
|
+
"\0" * 4 => "<~z~>",
|
20
|
+
"\0" * 5 => "<~z!!~>",
|
21
|
+
"A\0\0\0\0" => "<~5l^lb!!~>", # No z-abbreviation!
|
22
|
+
|
23
|
+
"A" => "<~5l~>",
|
24
|
+
"AB" => "<~5sb~>",
|
25
|
+
"ABC" => "<~5sdp~>",
|
26
|
+
"ABCD" => "<~5sdq,~>",
|
27
|
+
"ABCDE" => "<~5sdq,70~>",
|
28
|
+
"ABCDEF" => "<~5sdq,77I~>",
|
29
|
+
"ABCDEFG" => "<~5sdq,77Kc~>",
|
30
|
+
"ABCDEFGH" => "<~5sdq,77Kd<~>",
|
31
|
+
"ABCDEFGHI" => "<~5sdq,77Kd<8H~>",
|
32
|
+
"Ascii85" => "<~6$$OMBfIs~>",
|
33
|
+
|
34
|
+
'Antidisestablishmentarianism' => '<~6#LdYA8-*rF*(i"Ch[s(D.RU,@<-\'jDJ=0/~>',
|
35
|
+
|
36
|
+
# Dōmo arigatō, Mr. Roboto (according to Wikipedia)
|
37
|
+
'どうもありがとうミスターロボット' =>
|
38
|
+
"<~j+42iJVN3:K&_E6j+<0KJW/W?W8iG`j+EuaK\"9on^Z0sZj+FJoK:LtSKB%T?~>",
|
39
|
+
|
40
|
+
[Math::PI].pack('G') => "<~5RAV2<(&;T~>",
|
41
|
+
[Math::E].pack('G') => "<~5R\"n0M\\K6,~>"
|
42
|
+
}
|
43
|
+
|
44
|
+
it "#decode should be the inverse of #encode" do
|
45
|
+
# Generate a random string
|
46
|
+
test_str = String.new
|
47
|
+
(1 + rand(255)).times do
|
48
|
+
test_str << rand(256).chr
|
49
|
+
end
|
50
|
+
|
51
|
+
encoded = Ascii85.encode(test_str)
|
52
|
+
decoded = Ascii85.decode(encoded)
|
53
|
+
|
54
|
+
assert_equal decoded, test_str
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#encode" do
|
58
|
+
it "should encode all specified test-cases correctly" do
|
59
|
+
TEST_CASES.each_pair do |input, encoded|
|
60
|
+
assert_equal Ascii85.encode(input), encoded
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should encode Strings in different encodings correctly" do
|
65
|
+
unless String.new.respond_to?(:encoding)
|
66
|
+
skip(UNSUPPORTED_MSG)
|
67
|
+
end
|
68
|
+
|
69
|
+
input_EUC_JP = 'どうもありがとうミスターロボット'.encode('EUC-JP')
|
70
|
+
input_binary = input_EUC_JP.force_encoding('ASCII-8BIT')
|
71
|
+
|
72
|
+
assert_equal Ascii85.encode(input_EUC_JP), Ascii85.encode(input_binary)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should produce output lines no longer than specified" do
|
76
|
+
test_str = '0123456789' * 30
|
77
|
+
|
78
|
+
#
|
79
|
+
# No wrap
|
80
|
+
#
|
81
|
+
assert_equal Ascii85.encode(test_str, false).count("\n"), 0
|
82
|
+
|
83
|
+
#
|
84
|
+
# x characters per line, except for the last one
|
85
|
+
#
|
86
|
+
x = 2 + rand(255) # < test_str.length
|
87
|
+
encoded = Ascii85.encode(test_str, x)
|
88
|
+
|
89
|
+
# Determine the length of all lines
|
90
|
+
count_arr = []
|
91
|
+
encoded.each_line do |line|
|
92
|
+
count_arr << line.chomp.length
|
93
|
+
end
|
94
|
+
|
95
|
+
# The last line is allowed to be shorter than x, so remove it
|
96
|
+
count_arr.pop if count_arr.last <= x
|
97
|
+
|
98
|
+
# If the end-marker is on a line of its own, the next-to-last line is
|
99
|
+
# allowed to be shorter than specified by exactly one character
|
100
|
+
count_arr.pop if (encoded[-3].chr =~ /[\r\n]/) and (count_arr.last == x-1)
|
101
|
+
|
102
|
+
# Remove all line-lengths that are of length x from count_arr
|
103
|
+
count_arr.delete_if { |len| len == x }
|
104
|
+
|
105
|
+
# Now count_arr should be empty
|
106
|
+
assert_empty count_arr
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should not split the end-marker to achieve correct line length" do
|
110
|
+
assert_equal Ascii85.encode("\0" * 4, 4), "<~z\n~>"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#decode" do
|
115
|
+
it "should decode all specified test-cases correctly" do
|
116
|
+
TEST_CASES.each_pair do |decoded, input|
|
117
|
+
if String.new.respond_to?(:encoding)
|
118
|
+
assert_equal Ascii85.decode(input), decoded.dup.force_encoding('ASCII-8BIT')
|
119
|
+
else
|
120
|
+
assert_equal Ascii85.decode(input), decoded
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should accept valid input in encodings other than the default" do
|
126
|
+
unless String.new.respond_to?(:encoding)
|
127
|
+
skip(UNSUPPORTED_MSG)
|
128
|
+
end
|
129
|
+
|
130
|
+
input = "Ragnarök τέχνη русский язык I ♥ Ruby"
|
131
|
+
input_ascii85 = Ascii85.encode(input)
|
132
|
+
|
133
|
+
# Try to encode input_ascii85 in all possible encodings and see if we
|
134
|
+
# do the right thing in #decode.
|
135
|
+
Encoding.list.each do |encoding|
|
136
|
+
next if encoding.dummy?
|
137
|
+
next unless encoding.ascii_compatible?
|
138
|
+
|
139
|
+
# CP949 is a Microsoft Codepage for Korean, which apparently does not
|
140
|
+
# include a backslash, even though #ascii_compatible? returns true. This
|
141
|
+
# leads to an Ascii85::DecodingError, so we simply skip the encoding.
|
142
|
+
next if encoding.name == "CP949"
|
143
|
+
|
144
|
+
begin
|
145
|
+
to_test = input_ascii85.encode(encoding)
|
146
|
+
assert_equal Ascii85.decode(to_test).force_encoding('UTF-8'), input
|
147
|
+
rescue Encoding::ConverterNotFoundError
|
148
|
+
# Ignore this encoding
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should only process data within delimiters" do
|
154
|
+
assert_empty Ascii85.decode("<~~>")
|
155
|
+
assert_empty Ascii85.decode("Doesn't contain delimiters")
|
156
|
+
assert_empty Ascii85.decode("Mismatched ~> delimiters 1")
|
157
|
+
assert_empty Ascii85.decode("Mismatched <~ delimiters 2")
|
158
|
+
assert_empty Ascii85.decode("Mismatched ~><~ delimiters 3")
|
159
|
+
|
160
|
+
assert_equal Ascii85.decode("<~;KZGo~><~z~>"), "Ruby"
|
161
|
+
assert_equal Ascii85.decode("FooBar<~z~>BazQux"), "\0\0\0\0"
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should ignore whitespace" do
|
165
|
+
decoded = Ascii85.decode("<~6 #LdYA\r\08\n \n\n- *rF*(i\"Ch[s \t(D.RU,@ <-\'jDJ=0\f/~>")
|
166
|
+
assert_equal decoded, 'Antidisestablishmentarianism'
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should return ASCII-8BIT encoded strings" do
|
170
|
+
unless String.new.respond_to?(:encoding)
|
171
|
+
skip(UNSUPPORTED_MSG)
|
172
|
+
end
|
173
|
+
|
174
|
+
assert_equal Ascii85.decode("<~;KZGo~>").encoding.name, "ASCII-8BIT"
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "Error conditions" do
|
178
|
+
it "should raise DecodingError if it encounters a word >= 2**32" do
|
179
|
+
assert_raises(Ascii85::DecodingError) { Ascii85.decode('<~s8W-#~>') }
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should raise DecodingError if it encounters an invalid character" do
|
183
|
+
assert_raises(Ascii85::DecodingError) { Ascii85.decode('<~!!y!!~>') }
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should raise DecodingError if the last tuple consists of a single character" do
|
187
|
+
assert_raises(Ascii85::DecodingError) { Ascii85.decode('<~!~>') }
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should raise DecodingError if a z is found inside a 5-tuple" do
|
191
|
+
assert_raises(Ascii85::DecodingError) { Ascii85.decode('<~!!z!!~>') }
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
metadata
CHANGED
@@ -1,90 +1,100 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: Ascii85
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
6
|
+
authors:
|
7
|
+
- Johannes Holzfuß
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
dependencies:
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: hoe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.6.0
|
37
34
|
type: :development
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
41
38
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.6.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.2
|
55
|
+
description: Ascii85 provides methods to encode/decode Adobe's binary-to-text encoding
|
56
|
+
of the same name.
|
57
|
+
email: johannes@holzfuss.name
|
58
|
+
executables:
|
59
|
+
- ascii85
|
49
60
|
extensions: []
|
50
|
-
|
51
|
-
|
52
|
-
-
|
53
|
-
|
54
|
-
-
|
55
|
-
|
61
|
+
extra_rdoc_files:
|
62
|
+
- README.md
|
63
|
+
- LICENSE
|
64
|
+
files:
|
65
|
+
- ".travis.yml"
|
66
|
+
- Ascii85.gemspec
|
67
|
+
- Gemfile
|
56
68
|
- History.txt
|
57
|
-
-
|
58
|
-
- README.
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
59
71
|
- Rakefile
|
72
|
+
- bin/ascii85
|
73
|
+
- lib/Ascii85/version.rb
|
60
74
|
- lib/ascii85.rb
|
61
|
-
- spec/ascii85_spec.rb
|
62
|
-
|
63
|
-
|
75
|
+
- spec/lib/ascii85_spec.rb
|
76
|
+
homepage: https://github.com/DataWraith/ascii85gem/
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
64
80
|
post_install_message:
|
65
|
-
rdoc_options:
|
66
|
-
|
67
|
-
- README.txt
|
68
|
-
require_paths:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
69
83
|
- lib
|
70
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
72
86
|
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version:
|
75
|
-
|
76
|
-
|
77
|
-
requirements:
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
78
91
|
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version:
|
81
|
-
version:
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
82
94
|
requirements: []
|
83
|
-
|
84
|
-
rubyforge_project: ascii85
|
85
|
-
rubygems_version: 1.3.1
|
95
|
+
rubygems_version: 3.1.4
|
86
96
|
signing_key:
|
87
|
-
specification_version:
|
97
|
+
specification_version: 4
|
88
98
|
summary: Ascii85 encoder/decoder
|
89
|
-
test_files:
|
90
|
-
- spec/ascii85_spec.rb
|
99
|
+
test_files:
|
100
|
+
- spec/lib/ascii85_spec.rb
|
data.tar.gz.sig
DELETED
Binary file
|
data/Manifest.txt
DELETED
data/README.txt
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
= Ascii85
|
2
|
-
|
3
|
-
* http://ascii85.rubyforge.org
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Ascii85 is a simple gem that provides methods for encoding/decoding Adobe's
|
8
|
-
binary-to-text encoding of the same name.
|
9
|
-
|
10
|
-
See http://www.adobe.com/products/postscript/pdfs/PLRM.pdf page 131 and
|
11
|
-
http://en.wikipedia.org/wiki/Ascii85 for more information about the format.
|
12
|
-
|
13
|
-
|
14
|
-
== SYNOPSIS:
|
15
|
-
|
16
|
-
require 'rubygems'
|
17
|
-
require 'ascii85'
|
18
|
-
|
19
|
-
Ascii85::encode("Ruby")
|
20
|
-
=> "<~;KZGo~>"
|
21
|
-
|
22
|
-
Ascii85::decode("<~;KZGo~>")
|
23
|
-
=> "Ruby"
|
24
|
-
|
25
|
-
In addition, Ascii85::encode can take a second parameter that specifies the
|
26
|
-
length of the returned lines. The default is 80; use +false+ for unlimited.
|
27
|
-
|
28
|
-
Ascii85::decode expects the input to be enclosed in <~ and ~>. It ignores
|
29
|
-
everything outside of these.
|
30
|
-
|
31
|
-
|
32
|
-
== INSTALL:
|
33
|
-
|
34
|
-
* sudo gem install ascii85
|
35
|
-
|
36
|
-
|
37
|
-
== LICENSE:
|
38
|
-
|
39
|
-
(The MIT License)
|
40
|
-
|
41
|
-
Copyright (c) 2009 Johannes Holzfuß
|
42
|
-
|
43
|
-
Permission is hereby granted, free of charge, to any person obtaining a
|
44
|
-
copy of this software and associated documentation files (the "Software"),
|
45
|
-
to deal in the Software without restriction, including without limitation the
|
46
|
-
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
47
|
-
sell copies of the Software, and to permit persons to whom the Software is
|
48
|
-
furnished to do so, subject to the following conditions:
|
49
|
-
|
50
|
-
The above copyright notice and this permission notice shall be included in
|
51
|
-
all copies or substantial portions of the Software.
|
52
|
-
|
53
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
54
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
55
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
56
|
-
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
57
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
58
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
59
|
-
THE SOFTWARE.
|
data/spec/ascii85_spec.rb
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
-
|
5
|
-
require 'ascii85'
|
6
|
-
|
7
|
-
describe Ascii85 do
|
8
|
-
|
9
|
-
TEST_CASES = {
|
10
|
-
|
11
|
-
"" => "",
|
12
|
-
" " => "<~+9~>",
|
13
|
-
|
14
|
-
"\0" * 1 => "<~!!~>",
|
15
|
-
"\0" * 2 => "<~!!!~>",
|
16
|
-
"\0" * 3 => "<~!!!!~>",
|
17
|
-
"\0" * 4 => "<~z~>",
|
18
|
-
"\0" * 5 => "<~z!!~>",
|
19
|
-
"A\0\0\0\0" => "<~5l^lb!!~>", # No z-abbreviation!
|
20
|
-
|
21
|
-
"A" => "<~5l~>",
|
22
|
-
"AB" => "<~5sb~>",
|
23
|
-
"ABC" => "<~5sdp~>",
|
24
|
-
"ABCD" => "<~5sdq,~>",
|
25
|
-
"ABCDE" => "<~5sdq,70~>",
|
26
|
-
"ABCDEF" => "<~5sdq,77I~>",
|
27
|
-
"ABCDEFG" => "<~5sdq,77Kc~>",
|
28
|
-
"ABCDEFGH" => "<~5sdq,77Kd<~>",
|
29
|
-
"ABCDEFGHI" => "<~5sdq,77Kd<8H~>",
|
30
|
-
"Ascii85" => "<~6$$OMBfIs~>",
|
31
|
-
|
32
|
-
'Antidisestablishmentarianism' => '<~6#LdYA8-*rF*(i"Ch[s(D.RU,@<-\'jDJ=0/~>',
|
33
|
-
|
34
|
-
# Dōmo arigatō, Mr. Roboto (according to Wikipedia)
|
35
|
-
'どうもありがとうミスターロボット' =>
|
36
|
-
"<~j+42iJVN3:K&_E6j+<0KJW/W?W8iG`j+EuaK\"9on^Z0sZj+FJoK:LtSKB%T?~>",
|
37
|
-
|
38
|
-
[Math::PI].pack('G') => "<~5RAV2<(&;T~>",
|
39
|
-
[Math::E].pack('G') => "<~5R\"n0M\\K6,~>"
|
40
|
-
}
|
41
|
-
|
42
|
-
it "#decode should be the inverse of #encode" do
|
43
|
-
|
44
|
-
# Generate a random string
|
45
|
-
test_str = ""
|
46
|
-
(1 + rand(255)).times do
|
47
|
-
test_str += rand(256).chr
|
48
|
-
end
|
49
|
-
|
50
|
-
encoded = Ascii85::encode(test_str)
|
51
|
-
decoded = Ascii85::decode(encoded)
|
52
|
-
|
53
|
-
decoded.should == test_str
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "#encode" do
|
57
|
-
|
58
|
-
it "should encode all specified test-cases correctly" do
|
59
|
-
TEST_CASES.each_pair do |input, encoded|
|
60
|
-
Ascii85::encode(input).should == encoded
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should produce output lines no longer than specified" do
|
65
|
-
test_str = '0123456789' * 30
|
66
|
-
|
67
|
-
#
|
68
|
-
# No wrap
|
69
|
-
#
|
70
|
-
Ascii85::encode(test_str, false).count("\n").should == 0
|
71
|
-
|
72
|
-
#
|
73
|
-
# x characters per line, except for the last one
|
74
|
-
#
|
75
|
-
x = 2 + rand(255) # < test_str.length
|
76
|
-
encoded = Ascii85::encode(test_str, x)
|
77
|
-
|
78
|
-
# Determine the length of all lines
|
79
|
-
count_arr = []
|
80
|
-
encoded.each_line do |line|
|
81
|
-
count_arr << line.chomp.length
|
82
|
-
end
|
83
|
-
|
84
|
-
# The last line is allowed to be shorter than x, so remove it
|
85
|
-
count_arr.pop if count_arr.last <= x
|
86
|
-
|
87
|
-
# If the end-marker is on a line of its own, the next-to-last line is
|
88
|
-
# allowed to be shorter than specified by exactly one character
|
89
|
-
count_arr.pop if (encoded[-3].chr =~ /[\r\n]/) and (count_arr.last == x-1)
|
90
|
-
|
91
|
-
# Remove all line-lengths that are of length x from count_arr
|
92
|
-
count_arr.delete_if { |len| len == x }
|
93
|
-
|
94
|
-
# Now count_arr should be empty
|
95
|
-
count_arr.should be_empty
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should not split the end-marker to achieve correct line length" do
|
99
|
-
Ascii85::encode("\0" * 4, 4).should == "<~z\n~>"
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "#decode" do
|
105
|
-
|
106
|
-
it "should decode all specified test-cases correctly" do
|
107
|
-
TEST_CASES.each_pair do |decoded, input|
|
108
|
-
Ascii85::decode(input).should == decoded
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should ignore everything before/after the delimiter-pairs" do
|
113
|
-
Ascii85::decode("Doesn't contain delimiters").should == ''
|
114
|
-
Ascii85::decode("FooBar<~z~>BazQux").should == ("\0" * 4)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should ignore whitespace" do
|
118
|
-
decoded = Ascii85::decode("<~6 #LdYA\r\08\n \n\n- *rF*(i\"Ch[s \t(D.RU,@ <-\'jDJ=0\f/~>")
|
119
|
-
decoded.should == 'Antidisestablishmentarianism'
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "Error conditions" do
|
123
|
-
|
124
|
-
it "should raise DecodingError if it encounters a word >= 2**32" do
|
125
|
-
lambda {
|
126
|
-
Ascii85::decode('<~s8W-#~>')
|
127
|
-
}.should raise_error Ascii85::DecodingError
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should raise DecodingError if it encounters an invalid character" do
|
131
|
-
lambda {
|
132
|
-
Ascii85::decode('<~!!y!!~>')
|
133
|
-
}.should raise_error Ascii85::DecodingError
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should raise DecodingError if the last tuple consists of a single character" do
|
137
|
-
lambda {
|
138
|
-
Ascii85::decode('<~!~>')
|
139
|
-
}.should raise_error Ascii85::DecodingError
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should raise DecodingError if a z is found inside a 5-tuple" do
|
143
|
-
lambda {
|
144
|
-
Ascii85::decode('<~!!z!!~>')
|
145
|
-
}.should raise_error Ascii85::DecodingError
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|
metadata.gz.sig
DELETED
Binary file
|