Ascii85 1.1.1 → 2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e6f75c871ecc6415e5f3b26367ff204262a4063d807bb358ab9d068f747eb4a
4
- data.tar.gz: e641790ad3a207e4ef93d9afd2eb03c615455d52fd12f63fd6436f98bdf2c45f
3
+ metadata.gz: 32c27ed5387adae778bb5f1b5ef82da6ca878d6cd3128dd9a6d65c182ad89296
4
+ data.tar.gz: 81ba054e37db894fcb7411c143c6cfade2437bc91fd00956eeaf16233e96c25e
5
5
  SHA512:
6
- metadata.gz: 15ed44f2f78d878aba09fd781f16ae732dd9d55d0b4127b1d42ce736672059a5ac033f556c2b3757ae8bba4177eb3b9c31af27c1541b4ed75d0ac1c3cb288438
7
- data.tar.gz: d73d0f66ee001669d7ebda085334031a79a138c7522a886000133f6fdbdaabd05ac8a9185652eb4291c9865c44ca44e998cb17d79cde7191f0714b470ddf62ef
6
+ metadata.gz: da7757b98444ed6e745c0c9aa7930aa20346a273f94d316cb6eae473a6be293fd592320718f3d1eaef0ebc7d877deb4cb8ec0a43b13f4595835f56053abf3e5d
7
+ data.tar.gz: e881585d8b1f1cbdba501e7891daa2ed19b268c0b67d0cc8e424d944ce84d16c685b563bc18f34cd92db45b9a8e306e99e7b62b6d41908443eecdc15ee8bcf30
data/Ascii85.gemspec CHANGED
@@ -1,25 +1,26 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "Ascii85/version"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/Ascii85/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "Ascii85"
6
+ s.name = 'Ascii85'
7
7
  s.version = Ascii85::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.author = "Johannes Holzfuß"
10
- s.email = "johannes@holzfuss.name"
9
+ s.author = 'Johannes Holzfuß'
10
+ s.email = 'johannes@holzfuss.name'
11
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.}
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 "bundler", ">= 1.0.0"
17
- s.add_development_dependency "minitest",">= 2.6.0"
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 = ["lib"]
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,70 @@
1
+ # Ascii85 Changelog
2
+
3
+ ## [2.0.1] - 2024-09-15
4
+
5
+ ### Fixed
6
+
7
+ - Decoding binary data could lead to Encoding errors (Issue #8)
8
+
9
+ ## [2.0.0] - 2024-08-20
10
+
11
+ ### BREAKING CHANGES
12
+
13
+ - The minimum required Ruby version has been raised to 2.7.0.
14
+
15
+ ### Added
16
+
17
+ - `Ascii85.decode_raw` method that doesn't expect the input to be wrapped in `<~` and `~>` delimiters.
18
+ - `Ascii85.extract` method to extract encoded text from between `<~` and `~>` for feeding to `#decode_raw`.
19
+ - Option to pass an IO-object as input to `#encode` and `#decode_raw` instead of a String.
20
+ - 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.
21
+ - Streaming capability for `#encode` and `#decode_raw` when both input and output are IO objects, using constant memory.
22
+
23
+ ## [1.1.1] - 2024-05-09
24
+
25
+ ### Fixed
26
+
27
+ - Make `bin/ascii85` Ruby 3.2-compatible (thanks @tylerwillingham)
28
+ - Slightly improved error handling of `bin/ascii85`
29
+
30
+ ## [1.1.0] - 2020-11-11
31
+
32
+ ### Added
33
+
34
+ - Make use of frozen_string_literal (thanks @aliismayilov)
35
+
36
+ ### Changed
37
+
38
+ - Updated tests to use newer minitest syntax
39
+
40
+ ## [1.0.3] - 2018-01-25
41
+
42
+ ### Changed
43
+
44
+ - Updated the gem's metadata
45
+
46
+ ## [1.0.2] - 2012-09-16
47
+
48
+ ### Changed
49
+
50
+ - Changed test runner from RSpec to MiniSpec
51
+ - Added support for rubygems-test
52
+ - Minor changes to make packaging easier
53
+
54
+ ## [1.0.1] - 2011-05-05
55
+
56
+ ### Changed
57
+
58
+ - Removed `hoe` dependency in favor of `bundler`
59
+ - Minor corrections in the documentation
60
+
61
+ ## [1.0.0] - 2009-12-25
62
+
63
+ ### Added
64
+
65
+ - Ruby 1.9 compatibility
66
+ - Command-line en- and decoder
67
+
68
+ ## [0.9.0] - 2009-02-17
69
+
70
+ - Initial release
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in Ascii85.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -1,27 +1,30 @@
1
- **Status**: This project is in maintenance mode. I will not develop new features, but I will address Issues and Pull Requests.
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 simple gem that provides methods for encoding/decoding Adobe's
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 about the format.
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
- `sudo gem install Ascii85`
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 <~ 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.
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
- --version Output version information
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 :specs => :test
11
- task :tests => :test
12
- task :default => :test
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
- # encoding: utf-8
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
- @options = {
15
- :wrap => 80,
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
- opts.on( "-w", "--wrap COLUMN", Integer,
25
- "Wrap lines at COLUMN. Default is 80, use 0 for no wrapping") do |opt|
20
+ @options = {
21
+ wrap: 80,
22
+ action: :encode
23
+ }
26
24
 
27
- @options[:wrap] = opt.abs
28
- @options[:wrap] = false if opt.zero?
25
+ parse_options(argv)
29
26
  end
30
27
 
31
- opts.on( "-d", "--decode", "Decode the input") do
32
- @options[:decode] = true
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
- opts.on( "-h", "--help", "Display this help and exit") do
36
- puts opts
37
- exit
38
- end
68
+ return @in.binmode if fn == '-'
39
69
 
40
- opts.on( "--version", "Output version information") do |opt|
41
- puts "Ascii85 v#{Ascii85::VERSION},\nwritten by Johannes Holzfuß"
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
- remaining_args = opts.parse!
73
+ File.new(fn, 'rb')
74
+ end
46
75
 
47
- case remaining_args.size
48
- when 0
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
- # When opt_parse fails, it will raise an Exception that prints an error message,
58
- # but the program will continue running. However, @options[:file] will not be
59
- # set, so we can detect this condition and simply exit with an error status
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
- if @options[:file] == '-'
66
- @input = $stdin.binmode.read
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
- unless File.readable_real?(@options[:file])
73
- abort "File is not readable: \"#{@options[:file]}\""
88
+ def help
89
+ @parser
74
90
  end
75
91
 
76
- File.open(@options[:file], 'rb') do |f|
77
- @input = f.read
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 @options[:decode]
102
+ if File.basename($PROGRAM_NAME) == "ascii85"
82
103
  begin
83
- print Ascii85.decode(@input)
84
- rescue Ascii85::DecodingError => error
85
- abort "Decoding Error: #{error.message.to_s}"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ascii85
4
- VERSION = "1.1.1"
4
+ VERSION = '2.0.1'
5
5
  end