Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zinzout

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zinzout

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Zinzout

Zinzout is a naïve wrapper that uses Zlib::Gzip[Reader/Writer] to make dealing with gzipped files a little easier.

Basically:

  • When given a filename (and optionaly encoding), will attempt to open the appropriate file and correctly deal with gzippedness transparently
  • When given no filename, will simply return either STDIN or STDOUT

Examples


# The following code should work no matter which filename is used

# filename = nil # STDIN/STDOUT
# filename = 'textfile.txt'
filename = 'textfile.txt.gz'

outfilename = 'results_' + filename unless filename.nil?

infile = Zinzout.zin(filename, encoding: "utf-8")
outfile = Zinzout.zout(outfilename) # "utf-8" is the default

infile.each {|line| blah.blah }
outfile.puts "All done!"

# Much like using `File#open`, Zinzout will automatically close files
# (but not STDIN/STDOUT!) if given a block

Zinzout.zout(outfilename) do |outfile|
  Zinzout.zin(filename) do |infile|
    infile.each do |line|
      outfile.puts(line)
    end
  end
end

Determining gzippedness

Zinzout isn't smart. It's just convenient.

  • Zinzout::zin
    • No filename / filename.nil?: STDIN
    • Filename (String or Pathname):
      • Sniff the file to see if it's gzipped
      • Return either a Zlib::GzipReader or a File
  • Zinzout::zout
    • No filename / filename.nil?: STDOUT
    • Filename (String or Pathname) ends in .gz: Zlib::GzipWriter
    • Filename does not end in .gz: File

In particular, note that there's no attempt to sniff STDIN to see if it's gzipped, or to force compression before writing to STDOUT.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/billdueber/zinzout.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 28 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc