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

github.com/wangkuiyi/compress_io

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/wangkuiyi/compress_io

  • v0.0.0-20140907050920-c6fff9407b59
  • Source
  • Go
  • Socket score

Version published
Created
Source

Compress IO

Go standard libraries support reading/writing Gzip and Bzip2 data streams. However they do not have common interface. For example, compress/bzip2.NewReader returns io.Reader, where as compress/gzip.NewReader returns io.ReadCloser. This package encapsulates the compress package and provide unified interface.

Read

Read from a file while decompressing:

 f, e := os.Open(filename)
 if r := compress_io.NewReader(f, e, path.Ext(filename)); r != nil {
   defer r.Close()
   ... read from r ...
 }

If filename has extension ".bz2", r would decompress bzip2 data stream, or if it is ".gz", then r would decompress gzip data stream, otherwise, r does not invoke any decompression algorithm.

Write

Write to a file while compressing:

  f, e := os.Create(filename)
  if w := compress_io.NewWriter(f, e, path.Ext(filename)); w != nil {
    defer w.Close()
    ... write to w ...
  }

If filename has extension ".bz2", w would compress bzip2 data stream, or if it is ".gz", then r would compress gzip data stream, otherwise, r does not invoke any compression algorithm.

Caveat

Unfortunately, Go does not support taking multiple return values as parameters, as described in this discussion. This prevents us from writing:

if w := compress_io.NewCompressWriter(os.Create(filename), path.Ext(filename))

Instead, we have to write two lines:

f, e := os.Create(filename)
w := compress_io.NewWriter(f, e, path.Ext(filename))

So, there is a possibility to write:

defer f.Close()

instead of

defer w.Close()

However, defer w.Close() is what we want.

FAQs

Package last updated on 07 Sep 2014

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