zstd.cr v1.2.0
zstd
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
-
On OSX ensure that zstd is installed (
brew install zstd
).
On Linux it will be downloaded and compiled automatically if missing. -
Add the dependency to your
shard.yml
:dependencies: zstd: github: didactic-drunk/zstd.cr
-
Run
shards install
Usage
require "zstd"
Buffer API
cctx = Zstd::Compress::Context.new(level: 1)
cbuf = cctx.compress buf
dctx = Zstd::Decompress::Context.new
dbuf = dctx.decompress cbuf
Streaming API
buf = Bytes.new 5
mio = IO::Memory.new
Zstd::Compress::IO.open(mio, level: 1) do |cio|
cio.write buf
end
mio.rewind
str = Zstd::Decompress::IO.open(mio) do |dio|
dio.gets_to_end
end
Dictionary API
dict_buffer = File.read("dictionary").to_slice
dict = Zstd::Dict.new dict_buffer, level: 3
cctx = Zstd::Compress::Context.new dict: dict
dctx = Zstd::Decompress::Context.new dict: dict
# Compress or decompress using the Buffer or Streaming API's
p dict.dict_id
p dict.memsize
Contributing
- Fork it (https://github.com/your-github-user/zstd/fork)
- Install a formatting check git hook (ln -sf ../../scripts/git/pre-commit .git/hooks)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Didactic Drunk - creator and maintainer
Repository
zstd.cr
Owner
Statistic
- 41
- 1
- 1
- 5
- 0
- 5 months ago
- August 30, 2019
License
Links
Synced at
Wed, 06 Nov 2024 01:07:59 GMT
Languages