Gleam bindings to Erlang's zstd module regular.hexdocs.pm
gleam zstd erlang

Files
README.md

regular #

Package Version Hex Docs

gleam add regular@1
import regular

pub fn main() -> Nil {
  // Decompressing Zstd data.
  let compressed = <<>>
  let decompressed = regular.decompress(compressed)

  // Compressing to Zstd.
  let decompressed = <<"Wibble Wobble">>
  let compressed = regular.compress(decompressed)

  // Streaming compression.
  // Decompression works the same way.

  // Use a supervisor in your application.
  let assert Ok(compressor) = regular.new_compressor()
  let compressor = compressor.data

  let chunk_1 = <<"Hello, ">>
  let chunk_2 = <<"world">>
  let chunk_3 = <<"!">>

  // Or use a case statement on the returned CompressionResult,
  // to see if you need to run `stream_to_compressor` multiple times.
  let assert Ok(regular.CompressionFinished(compressed1)) =
    compressor
    |> regular.stream_to_compressor(waiting: 1000, chunk: chunk_1)

  // Enforce size limits if you're using this function. (more important if you're inflating)
  let assert Ok(compressed2) =
    compressor
    |> regular.stream_all_to_compressor(waiting: 1000, chunk: chunk_2)

  // Finish your frame with your last chunk and get the compressor ready for the next one.
  let assert Ok(compressed3) =
    compressor
    |> regular.finish_compressor_frame(waiting: 1000, chunk: chunk_3)
}

Further documentation can be found at https://regular.hexdocs.pm/.