Comandante/Zstd

An add-on for Comandante to allow for zstd reading/writing.

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  comandante-zstd:
    github: tghaleb/comandante-zstd
  1. Run shards install

Usage

require "comandante-zstd"

This is actually a wrapper around zstd.cr.

To write a string, or any type that has a to_slice method to file in one go,

str = "test"
Helper.write_zstd(str, file)

To Write Strings to a file using a block, and setting compressing level,

Helper.write_zstd(file, level: 19) do |io|
  io.print "test1"
  io.print "test2"
end

To read a file into a string,

x = Helper.read_zstd(file)

To read line by line

results = Array(String).new
Helper.read_zstd(file) do |x|
  results << x
end

module Comandante::Helper

Some helper functions

Class methods

.read_zstd(path)

Reads zstd file into a string

View source

.read_zstd(path, &) : Nil

Reads zstd line by line

read_zstd(path) { |line| puts line }
View source

.write_zstd(obj, path, level = 3) : Nil

Reads zstd file into a string

View source

.write_zstd(path, level = 3, &) : Nil

Reads zstd file line by line

View source