{"id":18103142,"url":"https://github.com/springmt/zstd-ruby","last_synced_at":"2026-01-08T07:18:21.815Z","repository":{"id":37924460,"uuid":"80843244","full_name":"SpringMT/zstd-ruby","owner":"SpringMT","description":"Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)","archived":false,"fork":false,"pushed_at":"2024-04-13T15:12:18.000Z","size":4698,"stargazers_count":61,"open_issues_count":2,"forks_count":14,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-14T04:07:01.959Z","etag":null,"topics":["ruby","zstd"],"latest_commit_sha":null,"homepage":"https://github.com/facebook/zstd","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SpringMT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-02-03T15:46:13.000Z","updated_at":"2024-04-26T06:20:06.869Z","dependencies_parsed_at":"2024-03-28T15:30:48.564Z","dependency_job_id":"df4a627f-902a-4967-969d-17f44b3065b9","html_url":"https://github.com/SpringMT/zstd-ruby","commit_stats":{"total_commits":112,"total_committers":9,"mean_commits":"12.444444444444445","dds":0.5178571428571428,"last_synced_commit":"93d601fbc98d437b63873df0834dfbe993c8e24a"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringMT%2Fzstd-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringMT%2Fzstd-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringMT%2Fzstd-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringMT%2Fzstd-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpringMT","download_url":"https://codeload.github.com/SpringMT/zstd-ruby/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361691,"owners_count":20926643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby","zstd"],"created_at":"2024-10-31T22:10:31.883Z","updated_at":"2026-01-08T07:18:21.806Z","avatar_url":"https://github.com/SpringMT.png","language":"C","readme":"[![Gem Version](https://badge.fury.io/rb/zstd-ruby.svg)](https://badge.fury.io/rb/zstd-ruby)\n![Build Status](https://github.com/SpringMT/zstd-ruby/actions/workflows/ruby.yml/badge.svg?branch=main)\n\n# zstd-ruby\n\nRuby binding for zstd(Zstandard - Fast real-time compression algorithm)\n\nSee https://github.com/facebook/zstd\n\n## Zstd version\n[v1.5.7](https://github.com/facebook/zstd/tree/v1.5.7)\n\n## Versioning Policy\n\nStarting from v2.0.0, this gem follows Semantic Versioning.\n\n- **Major version** (X.0.0): Breaking changes to the API\n- **Minor version** (X.Y.0): New features, including Zstd library version updates\n- **Patch version** (X.Y.Z): Bug fixes and other backward-compatible changes\n\n### Zstd Library Updates\n\nUpdates to the underlying Zstd library version will be released as **minor version** updates, as they may introduce new features or performance improvements while maintaining backward compatibility.\n\n**Note**: Versions prior to v2.0.0 followed the Zstd library versioning scheme with an additional patch number (e.g., 1.5.6.2). This approach has been replaced with semantic versioning to provide clearer expectations for API stability.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'zstd-ruby'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install zstd-ruby\n\n## Usage\n\n```ruby\nrequire 'zstd-ruby'\n```\n\n### Compression\n\n#### Simple Compression\n\n```ruby\ncompressed_data = Zstd.compress(data)\ncompressed_data = Zstd.compress(data, level: complession_level) # default compression_level is 3\n```\n\n#### Compression with Dictionary\n```ruby\n# dictionary is supposed to have been created using `zstd --train`\ncompressed_using_dict = Zstd.compress(\"\", dict: File.read('dictionary_file'))\n```\n\n#### Compression with CDict\n\nIf you use the same dictionary repeatedly, you can speed up the setup by creating CDict in advance:\n\n```ruby\ncdict = Zstd::CDict.new(File.read('dictionary_file'))\ncompressed_using_dict = Zstd.compress(\"\", dict: cdict)\n```\n\nThe compression_level can be specified on creating CDict.\n\n```ruby\ncdict = Zstd::CDict.new(File.read('dictionary_file'), 5)\ncompressed_using_dict = Zstd.compress(\"\", dict: cdict)\n```\n\n#### Streaming Compression\n```ruby\nstream = Zstd::StreamingCompress.new\nstream \u003c\u003c \"abc\" \u003c\u003c \"def\"\nres = stream.flush\nstream \u003c\u003c \"ghi\"\nres \u003c\u003c stream.finish\n```\n\nor\n\n```ruby\nstream = Zstd::StreamingCompress.new\nres = stream.compress(\"abc\")\nres \u003c\u003c stream.flush\nres \u003c\u003c stream.compress(\"def\")\nres \u003c\u003c stream.finish\n```\n\n#### Streaming Compression with Dictionary\n```ruby\nstream = Zstd::StreamingCompress.new(dict: File.read('dictionary_file'))\nstream \u003c\u003c \"abc\" \u003c\u003c \"def\"\nres = stream.flush\nstream \u003c\u003c \"ghi\"\nres \u003c\u003c stream.finish\n```\n\n#### Streaming Compression with level and Dictionary\n```ruby\nstream = Zstd::StreamingCompress.new(level: 5, dict: File.read('dictionary_file'))\nstream \u003c\u003c \"abc\" \u003c\u003c \"def\"\nres = stream.flush\nstream \u003c\u003c \"ghi\"\nres \u003c\u003c stream.finish\n```\n\n#### Streaming Compression with CDict of level 5\n```ruby\ncdict = Zstd::CDict.new(File.read('dictionary_file', 5)\nstream = Zstd::StreamingCompress.new(dict: cdict)\nstream \u003c\u003c \"abc\" \u003c\u003c \"def\"\nres = stream.flush\nstream \u003c\u003c \"ghi\"\nres \u003c\u003c stream.finish\n```\n\n### Decompression\n\n#### Simple Decompression\n\n```ruby\ndata = Zstd.decompress(compressed_data)\n```\n\n#### Decompression with Dictionary\n```ruby\n# dictionary is supposed to have been created using `zstd --train`\nZstd.decompress(compressed_using_dict, dict: File.read('dictionary_file'))\n```\n\n#### Decompression with DDict\n\nIf you use the same dictionary repeatedly, you can speed up the setup by creating DDict in advance:\n\n```ruby\nddict = Zstd::Ddict.new(File.read('dictionary_file'))\ndata = Zstd.compress(compressed_using_dict, ddict)\n```\n\n#### Streaming Decompression\n```ruby\ncstr = \"\" # Compressed data\nstream = Zstd::StreamingDecompress.new\nresult = ''\nresult \u003c\u003c stream.decompress(cstr[0, 10])\nresult \u003c\u003c stream.decompress(cstr[10..-1])\n```\n\n#### Streaming Decompression with dictionary\n```ruby\ncstr = \"\" # Compressed data\nstream = Zstd::StreamingDecompress.new(dict: File.read('dictionary_file'))\nresult = ''\nresult \u003c\u003c stream.decompress(cstr[0, 10])\nresult \u003c\u003c stream.decompress(cstr[10..-1])\n```\n\nDDict can also be specified to `dict:`.\n\n#### Streaming Decompression with Position Tracking\n\nIf you need to know how much of the input data was consumed during decompression, you can use the `decompress_with_pos` method:\n\n```ruby\ncstr = \"\" # Compressed data\nstream = Zstd::StreamingDecompress.new\nresult, consumed_bytes = stream.decompress_with_pos(cstr[0, 10])\n# result contains the decompressed data\n# consumed_bytes contains the number of bytes from input that were processed\n```\n\nThis is particularly useful when processing streaming data where you need to track the exact position in the input stream.\n\n### Skippable frame\n\n```ruby\ncompressed_data_with_skippable_frame = Zstd.write_skippable_frame(compressed_data, \"sample data\")\n\nZstd.read_skippable_frame(compressed_data_with_skippable_frame)\n# =\u003e \"sample data\"\n```\n\n### Stream Writer and Reader Wrapper\n**EXPERIMENTAL**\n\n* These features are experimental and may be subject to API changes in future releases.\n* There may be performance and compatibility issues, so extensive testing is required before production use.\n* If you have any questions, encounter bugs, or have suggestions, please report them via [GitHub issues](https://github.com/SpringMT/zstd-ruby/issues).\n\n#### Zstd::StreamWriter\n\n```ruby\nrequire 'stringio'\nrequire 'zstd-ruby'\n\nio = StringIO.new\nstream = Zstd::StreamWriter.new(io)\nstream.write(\"abc\")\nstream.finish\n\nio.rewind\n# Retrieve the compressed data\ncompressed_data = io.read\n```\n\n#### Zstd::StreamReader\n\n```ruby\nrequire 'stringio'\nrequire 'zstd-ruby' # Add the appropriate require statement if necessary\n\nio = StringIO.new(compressed_data)\nreader = Zstd::StreamReader.new(io)\n\n# Read and output the decompressed data\nputs reader.read(10)  # 'abc'\nputs reader.read(10)  # 'def'\nputs reader.read(10)  # '' (end of data)\n```\n\n\n## JRuby\nThis gem does not support JRuby.\n\nPlease consider using https://github.com/luben/zstd-jni.\n\nSample code is below.\n\n```\nrequire 'java'\nrequire_relative './zstd-jni-1.5.2-3.jar'\n\nstr = \"testtest\"\ncompressed = com.github.luben.zstd.Zstd.compress(str.to_java_bytes)\nputs com.github.luben.zstd.Zstd.decompress(compressed, str.length)\n```\n\n```\n% ls\ntest.rb              zstd-jni-1.5.2-3.jar\n% ruby -v\njruby 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]\n% ruby test.rb\ntesttest\n```\n\n## Development\n\nAfter 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.\n\nTo 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](https://rubygems.org).\n\n## Contributing\n\nBug 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](http://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause).\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringmt%2Fzstd-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspringmt%2Fzstd-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringmt%2Fzstd-ruby/lists"}