Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Crystal bindings to the Zstandard (zstd) compression library

NotificationsYou must be signed in to change notification settings

didactic-drunk/zstd.cr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crystal CIGitHub releaseGitHub commits since latest release (by date) for a branchDocs

Crystal bindings to the Zstandard (zstd) compression library

Features

  • Performance optimized. 20M small decompression messages/sec.
  • All API calls allow reusable buffers to reduce GC overhead.
  • No heap allocations after #initialize.
  • Crystal IO compatible Streaming API.
  • Snappy like buffer API for handling small messages.
  • export ZSTD_CLEVEL=1 sets the default compression level just like the zstd command line utilities.
  • Only require what you need for faster compilation. (require "zstd/compress/context")

Experimental Features. API's subject to change.

  • Custom dictionaries.

Todo

  • Linux: Auto install the most recent zstd if the system library is old or unavailable.
  • OSX: Auto install the most recent zstd if the system library is old or unavailable.
  • Support more zstd params.
  • More specs.

Installation

  1. OnOSX ensure that zstd is installed (brew install zstd).
    On Linux it will be downloaded and compiled automatically if missing.

  2. Add the dependency to yourshard.yml:

    dependencies:zstd:github:didactic-drunk/zstd.cr
  3. Runshards install

Usage

require"zstd"

Buffer API

cctx=Zstd::Compress::Context.new(level:1)cbuf= cctx.compress bufdctx=Zstd::Decompress::Context.newdbuf= dctx.decompress cbuf

Streaming API

buf=Bytes.new5mio=IO::Memory.newZstd::Compress::IO.open(mio,level:1)do |cio|  cio.write bufendmio.rewindstr=Zstd::Decompress::IO.open(mio)do |dio|  dio.gets_to_endend

Dictionary API

dict_buffer = File.read("dictionary").to_slicedict = Zstd::Dict.new dict_buffer, level: 3cctx = Zstd::Compress::Context.new dict: dictdctx = Zstd::Decompress::Context.new dict: dict# Compress or decompress using the Buffer or Streaming API'sp dict.dict_idp dict.memsize

Contributing

  1. Fork it (https://github.com/your-github-user/zstd/fork)
  2. Install a formatting check git hook (ln -sf ../../scripts/git/pre-commit .git/hooks)
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

Contributors


[8]ページ先頭

©2009-2025 Movatter.jp