All Projects → SpringMT → zstd-ruby

SpringMT / zstd-ruby

Licence: BSD-3-Clause license
Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)

Programming Languages

c
50402 projects - #5 most used programming language

Labels

Projects that are alternatives of or similar to zstd-ruby

Django Compression Middleware
Django middleware to compress responses using several algorithms.
Stars: ✭ 23 (-48.89%)
Mutual labels:  zstd
Zstdnet
Zstd wrapper for .NET
Stars: ✭ 176 (+291.11%)
Mutual labels:  zstd
ZRA
ZStandard Random Access (ZRA) allows random access inside an archive compressed using ZStandard
Stars: ✭ 21 (-53.33%)
Mutual labels:  zstd
Zstd Nginx Module
Nginx modules for the Zstandard compression
Stars: ✭ 64 (+42.22%)
Mutual labels:  zstd
7 Zip Zstd
7-Zip with support for Brotli, Fast-LZMA2, Lizard, LZ4, LZ5 and Zstandard
Stars: ✭ 2,150 (+4677.78%)
Mutual labels:  zstd
P7zip
A new p7zip fork with additional codecs and improvements (forked from https://sourceforge.net/projects/p7zip/).
Stars: ✭ 222 (+393.33%)
Mutual labels:  zstd
Lzbench
lzbench is an in-memory benchmark of open-source LZ77/LZSS/LZMA compressors
Stars: ✭ 490 (+988.89%)
Mutual labels:  zstd
ZstdKit
An Objective-C and Swift library for Zstd (Zstandard) compression and decompression.
Stars: ✭ 22 (-51.11%)
Mutual labels:  zstd
Zstd Rs
A rust binding for the zstd compression library.
Stars: ✭ 159 (+253.33%)
Mutual labels:  zstd
7-Zip-Filetype-Theme
7-Zip Filetype Theme Windows 10 and Windows 11
Stars: ✭ 145 (+222.22%)
Mutual labels:  zstd
Squashfs Tools Ng
A new set of tools and libraries for working with SquashFS images
Stars: ✭ 76 (+68.89%)
Mutual labels:  zstd
Libarchive
Multi-format archive and compression library
Stars: ✭ 1,625 (+3511.11%)
Mutual labels:  zstd
Python Zstandard
Python bindings to the Zstandard (zstd) compression library
Stars: ✭ 233 (+417.78%)
Mutual labels:  zstd
Hs Zstd
Bindings to the Zstandard library to make it usable from the Haskell programming language.
Stars: ✭ 45 (+0%)
Mutual labels:  zstd
zstdlite
Fast, configurable in-memory compression of R objects with zstd
Stars: ✭ 19 (-57.78%)
Mutual labels:  zstd
Pgbackrest
Reliable PostgreSQL Backup & Restore
Stars: ✭ 766 (+1602.22%)
Mutual labels:  zstd
Turbobench
Compression Benchmark
Stars: ✭ 211 (+368.89%)
Mutual labels:  zstd
zstd-rs
zstd-decoder in pure rust
Stars: ✭ 148 (+228.89%)
Mutual labels:  zstd
sparkzstd
A zstd decompressor written in golang
Stars: ✭ 45 (+0%)
Mutual labels:  zstd
pgzstd
Postgres module for Zstandard compression/decompression with preset dictionary support
Stars: ✭ 31 (-31.11%)
Mutual labels:  zstd

Gem Version Build Status

zstd-ruby

Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)

See https://github.com/facebook/zstd

Fork from https://github.com/jarredholman/ruby-zstd.

Zstd version

v1.5.2 (https://github.com/facebook/zstd/tree/v1.5.2)

Installation

Add this line to your application's Gemfile:

gem 'zstd-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install zstd-ruby

Usage

require 'zstd-ruby'

Simple Compression

compressed_data = Zstd.compress(data)
compressed_data = Zstd.compress(data, complession_level) # default compression_level is 0

Compression using Dictionary

# dictionary is supposed to have been created using `zstd --train`
compressed_using_dict = Zstd.compress_using_dict("", IO.read('dictionary_file'))

Streaming Compression

stream = Zstd::StreamingCompress.new
stream << "abc" << "def"
res = stream.flush
stream << "ghi"
res << stream.finish

or

stream = Zstd::StreamingCompress.new
res = stream.compress("abc")
res << stream.flush
res << stream.compress("def")
res << stream.finish

Simple Decompression

data = Zstd.decompress(compressed_data)

Decomporession using Dictionary

# dictionary is supposed to have been created using `zstd --train`
Zstd.decompress_using_dict(compressed_using_dict, IO.read('dictionary_file'))

Streaming Decompression

cstr = "" # Compressed data
stream = Zstd::StreamingDecompress.new
result = ''
result << stream.decompress(cstr[0, 10])
result << stream.decompress(cstr[10..-1])

JRuby

This gem does not support JRuby.

Please consider using https://github.com/luben/zstd-jni.

Sample code is below.

require 'java'
require_relative './zstd-jni-1.5.2-3.jar'

str = "testtest"
compressed = com.github.luben.zstd.Zstd.compress(str.to_java_bytes)
puts com.github.luben.zstd.Zstd.decompress(compressed, str.length)
% ls
test.rb              zstd-jni-1.5.2-3.jar
% ruby -v
jruby 9.3.2.0 (2.6.8) 2021-12-01 0b8223f905 OpenJDK 64-Bit Server VM 11.0.12+0 on 11.0.12+0 +jit [darwin-x86_64]
% ruby test.rb
testtest

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/SpringMT/zstd-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the BSD-3-Clause License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].