Crystal bindings to the Zstandard (zstd) compression library
Crystal bindings to the Zstandard (zstd) compression library
export ZSTD_CLEVEL=1
sets the default compression level just like the zstd command line utilities.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
require "zstd"
cctx = Zstd::Compress::Context.new(level: 1)
cbuf = cctx.compress buf
dctx = Zstd::Decompress::Context.new
dbuf = dctx.decompress cbuf
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
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
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)