zinzout 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 140303de5452b7727cff22f4a3e6d117df2d1a87b52815b4454b73186a19f4d3
4
+ data.tar.gz: 4c968b7ff19c1529ff4c0e084cbc127335b33ababa7ad0a07dc892d56ed07879
5
+ SHA512:
6
+ metadata.gz: bf901312d7c814460b0e9b7cd20b5a45d541a258a4a86466db5a3ce4bffc31e605117e301b6b19a0d449631e7ebf32e98c1a4d6ab7c1b9e39240c574800355f6
7
+ data.tar.gz: a9cb9e292f27812aee680cd1413c30cf5b13cd2d455f73b87442d0602584533048720c133d33a8988f07056a898fa4c81c87e9af47d2667b4bcf703ba2a62727
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .idea
13
+ *.iml
14
+ .tool-versions
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in zinzout.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ zinzout (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (12.3.3)
11
+ rspec (3.9.0)
12
+ rspec-core (~> 3.9.0)
13
+ rspec-expectations (~> 3.9.0)
14
+ rspec-mocks (~> 3.9.0)
15
+ rspec-core (3.9.2)
16
+ rspec-support (~> 3.9.3)
17
+ rspec-expectations (3.9.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.9.0)
20
+ rspec-mocks (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-support (3.9.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ rake (~> 12.0)
30
+ rspec (~> 3.0)
31
+ zinzout!
32
+
33
+ BUNDLED WITH
34
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Bill Dueber
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ # Zinzout
2
+
3
+ `Zinzout` is a naïve wrapper that uses Zlib::Gzip[Reader/Writer] to make
4
+ dealing with gzipped files a little easier.
5
+
6
+ _Basically_:
7
+ * When given a filename (and optionaly encoding), will attempt to open
8
+ the appropriate file and correctly deal with gzippedness transparently
9
+ * When given no filename, will simply return either STDIN or STDOUT
10
+
11
+ ## Examples
12
+
13
+ ```ruby
14
+
15
+ # The following code should work no matter which filename is used
16
+
17
+ # filename = nil # STDIN/STDOUT
18
+ # filename = 'textfile.txt'
19
+ filename = 'textfile.txt.gz'
20
+
21
+ outfilename = 'results_' + filename unless filename.nil?
22
+
23
+ infile = Zinzout.zin(filename, encoding: "utf-8")
24
+ outfile = Zinzout.zout(outfilename) # "utf-8" is the default
25
+
26
+ infile.each {|line| blah.blah }
27
+ outfile.puts "All done!"
28
+
29
+ # Much like using `File#open`, Zinzout will automatically close files
30
+ # (but not STDIN/STDOUT!) if given a block
31
+
32
+ Zinzout.zout(outfilename) do |outfile|
33
+ Zinzout.zin(filename) do |infile|
34
+ infile.each do |line|
35
+ outfile.puts(line)
36
+ end
37
+ end
38
+ end
39
+
40
+ ```
41
+
42
+ ## Determining gzippedness
43
+
44
+ `Zinzout` isn't smart. It's just convenient.
45
+
46
+ * `Zinzout::zin`
47
+ * _No filename / filename.nil?_: STDIN
48
+ * _Filename (String or Pathname)_:
49
+ * Sniff the file to see if it's gzipped
50
+ * Return either a `Zlib::GzipReader` or a `File`
51
+ * `Zinzout::zout`
52
+ * _No filename / filename.nil?_: STDOUT
53
+ * _Filename (String or Pathname) ends in .gz_: `Zlib::GzipWriter`
54
+ * _Filename does not end in .gz_: `File`
55
+
56
+ In particular, note that there's no attempt to sniff STDIN to see if
57
+ it's gzipped, or to force compression before writing to STDOUT.
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/billdueber/zinzout.
62
+
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "zinzout"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,98 @@
1
+ require "zinzout/version"
2
+ require 'zlib'
3
+
4
+ module Zinzout
5
+ class Error < StandardError; end
6
+
7
+ DEFAULT_ENCODING = "utf-8"
8
+
9
+ def self.zin(filename = nil, encoding: DEFAULT_ENCODING)
10
+ zin = Zin.new(filename, encoding)
11
+ if block_given?
12
+ yield zin.io
13
+ zin.close
14
+ end
15
+ zin.io
16
+ end
17
+
18
+ def self.zout(filename = nil, encoding: DEFAULT_ENCODING)
19
+ zout = Zout.new(filename, encoding)
20
+ if block_given?
21
+ yield zout.io
22
+ zout.close
23
+ nil
24
+ else
25
+ zout.io
26
+ end
27
+ end
28
+
29
+ class Zin
30
+ def self.new(filename, encoding)
31
+ if filename.nil?
32
+ ZinStdin.new
33
+ else
34
+ ZinFile.new(filename.to_s, encoding)
35
+ end
36
+ end
37
+ end
38
+
39
+ class Zout
40
+ def self.new(filename, encoding)
41
+ if filename.nil?
42
+ ZoutStdout.new
43
+ else
44
+ ZoutFile.new(filename.to_s, encoding)
45
+ end
46
+ end
47
+ end
48
+
49
+
50
+ class ZinFile
51
+ attr_reader :io
52
+
53
+ def initialize(filename, encoding)
54
+ @io = io_from_file(filename, encoding)
55
+ end
56
+
57
+ def io_from_file(filename, encoding)
58
+ Zlib::GzipReader.open(filename, encoding: encoding)
59
+ rescue Zlib::GzipFile::Error
60
+ ::File.open(filename, 'r', encoding: encoding)
61
+ end
62
+
63
+ def close
64
+ @io.close
65
+ end
66
+ end
67
+
68
+ class ZoutFile < ZinFile
69
+ def io_from_file(filename, encoding)
70
+ if /\.gz\Z/.match(filename)
71
+ Zlib::GzipWriter.open(filename, encoding: encoding)
72
+ else
73
+ File.open(filename, 'w', encoding: encoding)
74
+ end
75
+ end
76
+ end
77
+
78
+
79
+ class ZinStdin
80
+ attr_reader :io
81
+
82
+ def initialize
83
+ @io = STDIN
84
+ end
85
+
86
+ def close
87
+ # no op
88
+ end
89
+ end
90
+
91
+ class ZoutStdout < ZinStdin
92
+ def initialize
93
+ @io = STDOUT
94
+ end
95
+ end
96
+
97
+
98
+ end
@@ -0,0 +1,3 @@
1
+ module Zinzout
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/zinzout/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "zinzout"
5
+ spec.version = Zinzout::VERSION
6
+ spec.authors = ["Bill Dueber"]
7
+ spec.email = ["bill@dueber.com"]
8
+
9
+ spec.summary = %q{Transparently open gzipped files for input/output}
10
+ spec.homepage = "https://github.com/billdueber/zinzout"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.metadata["changelog_uri"] = spec.homepage + '/CHANGELOG.md'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zinzout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bill Dueber
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - bill@dueber.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - lib/zinzout.rb
31
+ - lib/zinzout/version.rb
32
+ - zinzout.gemspec
33
+ homepage: https://github.com/billdueber/zinzout
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/billdueber/zinzout
38
+ source_code_uri: https://github.com/billdueber/zinzout
39
+ changelog_uri: https://github.com/billdueber/zinzout/CHANGELOG.md
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.3.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.1.3
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Transparently open gzipped files for input/output
59
+ test_files: []