Snappy Ruby Bindings
Ruby bindings for Google's Snappy compression library (https://github.com/google/snappy) with bundled libsnappy source - no system dependencies required!
Features
- Fast compression and decompression using Snappy
- Bundled Snappy library - no need to install libsnappy separately
- File-based compression/decompression with input and output filename support
- Compression level support (compatible with Snappy's range: 1-9)
- Compatible with Ruby 3.0+
- Works on Linux, macOS, and Windows
Installation
Add this line to your application's Gemfile:
gem 'snappy-ruby'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install snappy-ruby
Usage
require 'snappy'
# Compress data from a file
Snappy.compress_file('input.txt', 'output.snappy', level: 6)
# Decompress data to a file
Snappy.decompress_file('output.snappy', 'decompressed.txt')
# In-memory compression/decompression
compressed = Snappy.compress('Hello, World!', level: 6)
decompressed = Snappy.decompress(compressed)
Development
After checking out the repo, run bundle install to install dependencies. Then, run rake spec to run the tests.
Requirements
- Ruby 3.0 or higher
- Ruby development headers (ruby-dev)
- C++ compiler with C++11 support
Note: The Snappy library is bundled with this gem, so you don't need to install libsnappy separately!
Installing Build Dependencies
On Ubuntu/Debian:
sudo apt-get install ruby-dev build-essential
On macOS (requires Xcode Command Line Tools):
xcode-select --install
On Fedora/RHEL:
sudo dnf install ruby-devel gcc-c++ make
License
The gem is available as open source under the terms of the MIT License.