search fire star recently

snappy

Snappy compression format reader/writer for Crystal

snappy compression-format crystal-bindings
0.1.1 Latest release Yanked release released
naqvis/snappy
6

Build Status GitHub release Docs

Crystal Snappy

Pure Crystal implementation of Snappy compression format. This implementation supports more common case Snappy Framing Format.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      snappy:
        github: naqvis/snappy
    
  2. Run shards install

Usage

require "snappy"

Module provides both Snappy::Reader and Snappy::Writer for use with streams like IO and/or files. It also provides Snappy#decode and Snappy#encode for uncompressing and compressing block formats.

Example: decompress a snappy file

require "snappy"

File.write("file.sz", Bytes[255, 6, 0, 0, 115, 78, 97, 80, 112, 89, 1, 8, 0, 0, 104, 16, 130, 162, 97, 98, 99, 100])

string = File.open("file.sz") do |file|
   Snappy::Reader.open(file) do |sz|
     sz.gets_to_end
   end
end
string # => "abcd"

Example: compress a file to snappy format

require "snappy"

File.write("file.txt", "abcd")

File.open("./file.txt", "r") do |input_file|
  File.open("./file.sz", "w") do |output_file|
    Snappy::Writer.open(output_file) do |sz|
      IO.copy(input_file, sz)
    end
  end
end

Refer to specs for usage examples.

Development

To run all tests:

crystal spec

Contributing

  1. Fork it (https://github.com/naqvis/snappy/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

snappy:
  github: naqvis/snappy
  version: ~> 0.1.1

Authors

  • Ali Naqvi

License

MIT

Crystal

0.31.1

Dependencies 0

Development Dependencies 0

Dependents 0

Last synced .