Ascii85 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Ascii85.gemspec +15 -14
- data/CHANGELOG.md +64 -0
- data/Gemfile +3 -1
- data/README.md +28 -12
- data/Rakefile +5 -3
- data/bin/ascii85 +79 -56
- data/lib/Ascii85/version.rb +1 -1
- data/lib/ascii85.rb +396 -164
- data/spec/bin/cli_spec.rb +211 -0
- data/spec/lib/ascii85_spec.rb +152 -107
- metadata +19 -25
- data/History.txt +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e134217a95580db89dd446ac40511345e8c0a317be617b9b04e2ac8ca5db9670
|
4
|
+
data.tar.gz: bcc1f3f71f2f5748958825602ef58c7365ef52f7fe3265a9409fd1b84b5c8d4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c15434410e46485ada5dcc04929092f77da1533861d22ffe65ab0e2f1e8300a821b16524fbeb5ad137cc6a139232a5684dfe6fd34c5ad33e19d68a95d3f604e
|
7
|
+
data.tar.gz: a397048e6009d3adf0c2582cfe9dbd913f6b8888c19fbf48939b1a7ab48de704fa7fb76253d5d3a05d105215fb9e9f2da299d91c12cf5e6c2a3cb2636a2b6f8a
|
data/Ascii85.gemspec
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/Ascii85/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
6
|
+
s.name = 'Ascii85'
|
7
7
|
s.version = Ascii85::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.author =
|
10
|
-
s.email =
|
9
|
+
s.author = 'Johannes Holzfuß'
|
10
|
+
s.email = 'johannes@holzfuss.name'
|
11
11
|
s.license = 'MIT'
|
12
|
-
s.homepage =
|
13
|
-
s.summary =
|
14
|
-
s.description =
|
12
|
+
s.homepage = 'https://github.com/DataWraith/ascii85gem/'
|
13
|
+
s.summary = 'Ascii85 encoder/decoder'
|
14
|
+
s.description = "Ascii85 provides methods to encode/decode Adobe's binary-to-text encoding of the same name."
|
15
|
+
|
16
|
+
s.required_ruby_version = '>= 2.7.0'
|
15
17
|
|
16
|
-
s.add_development_dependency
|
17
|
-
s.add_development_dependency
|
18
|
-
s.add_development_dependency "rake", ">= 0.9.2"
|
18
|
+
s.add_development_dependency 'minitest', '~> 5', '>= 5.12.0'
|
19
|
+
s.add_development_dependency 'rake', '~> 13'
|
19
20
|
|
20
21
|
s.files = `git ls-files`.split("\n") - ['.gitignore', '.github/workflows/ruby.yml']
|
21
22
|
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 = [
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
24
|
+
s.require_paths = ['lib']
|
24
25
|
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
25
26
|
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Ascii85 Changelog
|
2
|
+
|
3
|
+
## [2.0.0] - 2024-08-20
|
4
|
+
|
5
|
+
### BREAKING CHANGES
|
6
|
+
|
7
|
+
- The minimum required Ruby version has been raised to 2.7.0.
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- `Ascii85.decode_raw` method that doesn't expect the input to be wrapped in `<~` and `~>` delimiters.
|
12
|
+
- `Ascii85.extract` method to extract encoded text from between `<~` and `~>` for feeding to `#decode_raw`.
|
13
|
+
- Option to pass an IO-object as input to `#encode` and `#decode_raw` instead of a String.
|
14
|
+
- Option to pass an IO-object to `#encode` and `#decode_raw` for output. Output is written to the object instead of being returned as a String.
|
15
|
+
- Streaming capability for `#encode` and `#decode_raw` when both input and output are IO objects, using constant memory.
|
16
|
+
|
17
|
+
## [1.1.1] - 2024-05-09
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
21
|
+
- Make `bin/ascii85` Ruby 3.2-compatible (thanks @tylerwillingham)
|
22
|
+
- Slightly improved error handling of `bin/ascii85`
|
23
|
+
|
24
|
+
## [1.1.0] - 2020-11-11
|
25
|
+
|
26
|
+
### Added
|
27
|
+
|
28
|
+
- Make use of frozen_string_literal (thanks @aliismayilov)
|
29
|
+
|
30
|
+
### Changed
|
31
|
+
|
32
|
+
- Updated tests to use newer minitest syntax
|
33
|
+
|
34
|
+
## [1.0.3] - 2018-01-25
|
35
|
+
|
36
|
+
### Changed
|
37
|
+
|
38
|
+
- Updated the gem's metadata
|
39
|
+
|
40
|
+
## [1.0.2] - 2012-09-16
|
41
|
+
|
42
|
+
### Changed
|
43
|
+
|
44
|
+
- Changed test runner from RSpec to MiniSpec
|
45
|
+
- Added support for rubygems-test
|
46
|
+
- Minor changes to make packaging easier
|
47
|
+
|
48
|
+
## [1.0.1] - 2011-05-05
|
49
|
+
|
50
|
+
### Changed
|
51
|
+
|
52
|
+
- Removed `hoe` dependency in favor of `bundler`
|
53
|
+
- Minor corrections in the documentation
|
54
|
+
|
55
|
+
## [1.0.0] - 2009-12-25
|
56
|
+
|
57
|
+
### Added
|
58
|
+
|
59
|
+
- Ruby 1.9 compatibility
|
60
|
+
- Command-line en- and decoder
|
61
|
+
|
62
|
+
## [0.9.0] - 2009-02-17
|
63
|
+
|
64
|
+
- Initial release
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,27 +1,30 @@
|
|
1
|
-
**Status**: This project is
|
1
|
+
**Status**: This project is feature-complete. With the exception of fixes to reported bugs, no further development will take place.
|
2
2
|
|
3
3
|
# Ascii85
|
4
4
|
|
5
5
|
## Description
|
6
6
|
|
7
|
-
Ascii85 is a
|
7
|
+
Ascii85 is a Ruby gem that provides methods for encoding/decoding Adobe's
|
8
8
|
binary-to-text encoding of the same name.
|
9
9
|
|
10
10
|
See the Adobe PostScript Language Reference ([archived version][PLRM]) page 131
|
11
|
-
and https://en.wikipedia.org/wiki/Ascii85 for more information
|
11
|
+
and [Wikipedia](https://en.wikipedia.org/wiki/Ascii85) for more information
|
12
|
+
about the format.
|
12
13
|
|
13
14
|
[PLRM]: https://web.archive.org/web/20161222092741/https://www.adobe.com/products/postscript/pdfs/PLRM.pdf
|
14
15
|
|
15
16
|
|
16
17
|
## Installation
|
17
18
|
|
18
|
-
|
19
|
+
`$ gem install Ascii85`
|
20
|
+
|
21
|
+
> [!IMPORTANT]
|
22
|
+
> Note that the gem name is capitalized.
|
19
23
|
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
23
|
-
```
|
24
|
-
require 'rubygems'
|
27
|
+
```ruby
|
25
28
|
require 'ascii85'
|
26
29
|
|
27
30
|
Ascii85.encode("Ruby")
|
@@ -29,15 +32,28 @@ Ascii85.encode("Ruby")
|
|
29
32
|
|
30
33
|
Ascii85.decode("<~;KZGo~>")
|
31
34
|
=> "Ruby"
|
35
|
+
|
36
|
+
Ascii85.extract("Foo<~;KZGo~>Bar")
|
37
|
+
=> ";KZGo"
|
38
|
+
|
39
|
+
Ascii85.decode_raw(";KZGo")
|
40
|
+
=> "Ruby"
|
32
41
|
```
|
33
42
|
|
34
|
-
In addition, Ascii85.encode can take a second parameter that specifies the
|
43
|
+
In addition, `Ascii85.encode` can take a second parameter that specifies the
|
35
44
|
length of the returned lines. The default is 80; use `false` for unlimited.
|
36
45
|
|
37
|
-
Ascii85.decode expects the input to be enclosed in
|
38
|
-
ignores everything outside of these
|
39
|
-
|
40
|
-
|
46
|
+
`Ascii85.decode` expects the input to be enclosed in `<~` and `~>` — it
|
47
|
+
ignores everything outside of these, while `Ascii85.decode_raw` assumes that
|
48
|
+
the entire String passed in is encoded in Ascii85. If you need to, you can use
|
49
|
+
`Ascii85.extract` to find and extract the first substring of the input that is
|
50
|
+
enclosed by the `<~` and `~>` delimiters.
|
51
|
+
|
52
|
+
The output of `Ascii85.decode` and `Ascii85.decode_raw` will be a String that
|
53
|
+
has the `ASCII-8BIT` encoding, so you may have to use `String#force_encoding` to
|
54
|
+
convert it to the desired encoding.
|
55
|
+
|
56
|
+
For further options, see the [Documentation](https://www.rubydoc.info/gems/Ascii85/).
|
41
57
|
|
42
58
|
|
43
59
|
## Command-line utility
|
@@ -52,7 +68,7 @@ Encodes or decodes FILE or STDIN using Ascii85 and writes to STDOUT.
|
|
52
68
|
-w, --wrap COLUMN Wrap lines at COLUMN. Default is 80, use 0 for no wrapping
|
53
69
|
-d, --decode Decode the input
|
54
70
|
-h, --help Display this help and exit
|
55
|
-
|
71
|
+
-V, --version Output version information
|
56
72
|
```
|
57
73
|
|
58
74
|
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler'
|
2
4
|
Bundler::GemHelper.install_tasks
|
3
5
|
|
@@ -7,6 +9,6 @@ Rake::TestTask.new do |t|
|
|
7
9
|
t.test_files = FileList['spec/**/*_spec.rb']
|
8
10
|
end
|
9
11
|
|
10
|
-
task :
|
11
|
-
task :
|
12
|
-
task :
|
12
|
+
task specs: :test
|
13
|
+
task tests: :test
|
14
|
+
task default: :test
|
data/bin/ascii85
CHANGED
@@ -1,89 +1,112 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
4
|
#
|
5
5
|
# A simple command-line tool to de- and encode Ascii85, modeled after `base64`
|
6
6
|
# from the GNU Coreutils.
|
7
7
|
#
|
8
8
|
|
9
|
-
|
10
|
-
require "optparse"
|
9
|
+
require 'optparse'
|
11
10
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'ascii85')
|
12
11
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'Ascii85', 'version')
|
13
12
|
|
14
|
-
|
15
|
-
:
|
16
|
-
:decode => false
|
17
|
-
}
|
18
|
-
|
19
|
-
ARGV.options do |opts|
|
20
|
-
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] [FILE]\n" +
|
21
|
-
"Encodes or decodes FILE or STDIN using Ascii85 and writes to STDOUT."
|
13
|
+
class CLI
|
14
|
+
attr_reader :options
|
22
15
|
|
16
|
+
def initialize(argv, stdin: $stdin, stdout: $stdout)
|
17
|
+
@in = stdin
|
18
|
+
@out = stdout
|
23
19
|
|
24
|
-
|
25
|
-
|
20
|
+
@options = {
|
21
|
+
wrap: 80,
|
22
|
+
action: :encode
|
23
|
+
}
|
26
24
|
|
27
|
-
|
28
|
-
@options[:wrap] = false if opt.zero?
|
25
|
+
parse_options(argv)
|
29
26
|
end
|
30
27
|
|
31
|
-
|
32
|
-
@
|
28
|
+
def parse_options(argv)
|
29
|
+
@parser = OptionParser.new do |opts|
|
30
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] [FILE]\n" \
|
31
|
+
'Encodes or decodes FILE or STDIN using Ascii85 and writes to STDOUT.'
|
32
|
+
|
33
|
+
opts.on('-w', '--wrap COLUMN', Integer,
|
34
|
+
'Wrap lines at COLUMN. Default is 80, use 0 for no wrapping') do |opt|
|
35
|
+
@options[:wrap] = opt.abs
|
36
|
+
@options[:wrap] = false if opt.zero?
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on('-d', '--decode', 'Decode the input') do
|
40
|
+
@options[:action] = :decode
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on('-h', '--help', 'Display this help and exit') do
|
44
|
+
@options[:action] = :help
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on('-V', '--version', 'Output version information') do |_opt|
|
48
|
+
@options[:action] = :version
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
remaining_args = @parser.parse!(argv)
|
54
|
+
|
55
|
+
case remaining_args.size
|
56
|
+
when 0
|
57
|
+
@options[:file] = '-'
|
58
|
+
when 1
|
59
|
+
@options[:file] = remaining_args.first
|
60
|
+
else
|
61
|
+
raise(OptionParser::ParseError, "Superfluous operand(s): \"#{remaining_args[1..].join('", "')}\"")
|
62
|
+
end
|
33
63
|
end
|
64
|
+
|
65
|
+
def input
|
66
|
+
fn = @options[:file]
|
34
67
|
|
35
|
-
|
36
|
-
puts opts
|
37
|
-
exit
|
38
|
-
end
|
68
|
+
return @in.binmode if fn == '-'
|
39
69
|
|
40
|
-
|
41
|
-
|
42
|
-
exit
|
43
|
-
end
|
70
|
+
raise(StandardError, "File not found: \"#{fn}\"") unless File.exist?(fn)
|
71
|
+
raise(StandardError, "File is not readable: \"#{fn}\"") unless File.readable_real?(fn)
|
44
72
|
|
45
|
-
|
73
|
+
File.new(fn, 'rb')
|
74
|
+
end
|
46
75
|
|
47
|
-
|
48
|
-
|
49
|
-
@options[:file] = '-'
|
50
|
-
when 1
|
51
|
-
@options[:file] = remaining_args.first
|
52
|
-
else
|
53
|
-
abort "Superfluous operand(s): \"#{remaining_args.join('", "')}\""
|
76
|
+
def decode
|
77
|
+
Ascii85.decode(input.read, out: @out)
|
54
78
|
end
|
55
|
-
end
|
56
79
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
# code while OptParse prints out the error message.
|
61
|
-
if @options[:file].nil?
|
62
|
-
exit 1
|
63
|
-
end
|
80
|
+
def encode
|
81
|
+
Ascii85.encode(input, @options[:wrap], out: @out)
|
82
|
+
end
|
64
83
|
|
65
|
-
|
66
|
-
|
67
|
-
else
|
68
|
-
unless File.exist?(@options[:file])
|
69
|
-
abort "File not found: \"#{@options[:file]}\""
|
84
|
+
def version
|
85
|
+
"Ascii85 v#{Ascii85::VERSION},\nwritten by Johannes Holzfuß"
|
70
86
|
end
|
71
87
|
|
72
|
-
|
73
|
-
|
88
|
+
def help
|
89
|
+
@parser
|
74
90
|
end
|
75
91
|
|
76
|
-
|
77
|
-
@
|
92
|
+
def call
|
93
|
+
case @options[:action]
|
94
|
+
when :help then @out.puts help
|
95
|
+
when :version then @out.puts version
|
96
|
+
when :encode then encode
|
97
|
+
when :decode then decode
|
98
|
+
end
|
78
99
|
end
|
79
100
|
end
|
80
101
|
|
81
|
-
if
|
102
|
+
if File.basename($PROGRAM_NAME) == "ascii85"
|
82
103
|
begin
|
83
|
-
|
84
|
-
rescue
|
85
|
-
abort
|
104
|
+
CLI.new(ARGV).call
|
105
|
+
rescue OptionParser::ParseError => e
|
106
|
+
abort e.message
|
107
|
+
rescue Ascii85::DecodingError => e
|
108
|
+
abort "Decoding Error: #{e.message}"
|
109
|
+
rescue StandardError => e
|
110
|
+
abort "Error: #{e.message}"
|
86
111
|
end
|
87
|
-
else
|
88
|
-
print Ascii85.encode(@input, @options[:wrap])
|
89
112
|
end
|
data/lib/Ascii85/version.rb
CHANGED