• Stars
    star
    18
  • Rank 1,208,065 (Top 24 %)
  • Language
    Crystal
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Snappy compression format reader/writer for Crystal

Crystal Snappy

CI GitHub release Docs

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 Compress::Snappy::Reader and Compress::Snappy::Writer for use with streams like IO and/or files. It also provides Compress::Snappy#decode and Compress::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|
   Compress::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|
    Compress::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

More Repositories

1

webview

Crystal bindings to Webview library
C++
92
star
2

wasmer-crystal

WebAssembly runtime for Crystal
Crystal
89
star
3

crystal-vips

Crystal bindings for the libvips image processing library.
Crystal
39
star
4

crystar

Crystal language Tar Module implements access to tar archives.
Crystal
38
star
5

crystal-html5

Crystal implementation of HTML5-Compliant Tokenizer and Parser with XPath & CSS Selector support
Crystal
35
star
6

CrysDA

Crystal library for Data Analysis, Wrangling, Munging
Crystal
23
star
7

cryplot

Crystal plotting library powered by gnuplot
Crystal
22
star
8

brotli.cr

Crystal bindings to the Google brotli compression library
Crystal
22
star
9

playwright-cr

Crystal version of the Playwright testing and automation library.
Crystal
19
star
10

cr-xmpp

XMPP/Jabber Library for Crystal
Crystal
16
star
11

lz4.cr

Crystal bindings to the LZ4 compression library
Crystal
15
star
12

xz.cr

Crystal bindings to the xz (lzma) compression library
Crystal
14
star
13

crystal-xpath2

XPath implemenation in Pure Crystal
Crystal
11
star
14

crystal-odbc

ODBC connector for Crystal
Crystal
11
star
15

uni_text_seg

Unicode Text Segmentation for Crystal. Currently supports determination of graphemes cluster boundaries.
Crystal
6
star
16

uni_char_width

Provides methods to get fixed width of unicode character or string
Crystal
6
star
17

magic.cr

Crystal bindings to libmagic
Crystal
5
star
18

crystal-fnv

Crystal Implementation of Fowler–Noll–Vo hash
Crystal
5
star
19

poi4go

Apache POI port to Golang
Go
4
star
20

containerregistry.cr

Crystal library for working with container registries.
Crystal
4
star
21

json-xpath

Provide XPath support on JSON document
Crystal
4
star