zstd-native-ruby

Native Ruby bindings for the Facebook Zstandard (zstd) compression library.

Installation

Add this line to your application's Gemfile:

gem 'zstd-native-ruby'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install zstd-native-ruby

Usage

require 'zstd_native'

# Simple compression
data = "Hello, World!" * 100
compressed = ZstdNative.compress(data)
decompressed = ZstdNative.decompress(compressed)

# With compression level (1-22, default is 3)
compressed = ZstdNative.compress(data, 10)

# Streaming compression
stream = ZstdNative::CStream.new(level: 5)
stream.compress("chunk1")
stream.compress("chunk2")
compressed_data = stream.finish

# Streaming decompression
dstream = ZstdNative::DStream.new
dstream.decompress(compressed_data)

# Dictionary compression
dict = ZstdNative::CDict.new(dictionary_data)
compressed = ZstdNative.compress_using_dict(data, dict)

ddict = ZstdNative::DDict.new(dictionary_data)
decompressed = ZstdNative.decompress_using_dict(compressed, ddict)

Features

  • Simple compression and decompression
  • Streaming compression and decompression
  • Dictionary support
  • Full access to all zstd.h API functions
  • Native performance

Development

After checking out the repo, run:

$ bundle install
$ rake compile
$ rake test

License

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

Credits

This gem wraps the Facebook Zstandard library: https://github.com/facebook/zstd