A small zlib/DEFLATE implementation in MoonBit (ported from yazi).
let data = b"hello world"
let compressed = compress(data, Format::Zlib, CompressionLevel::Default)
let (decompressed, checksum) = decompress(Bytes::from_array(compressed), Format::Zlib)
inspect(Bytes::from_array(decompressed) == data, content="true")
inspect(checksum == Some(Adler32::from_buf(data).finish()), content="true")let out : Array[Byte] = []
let encoder = Encoder()
encoder.set_format(Format::Raw)
let stream = encoder.stream_into_vec(out)
stream.write(b"hello ")
stream.write(b"world")
stream.finish() |> ignore
let decoder = Decoder()
decoder.set_format(Format::Raw)
let (plain, _) = decompress(Bytes::from_array(out), Format::Raw)
inspect(Bytes::from_array(plain) == b"hello world", content="true")type YaziErrorpub(all) enum CompressionLevel {
NoCompression
BestSpeed
Default
BestSize
Specific(UInt)
}pub(all) enum CompressionStrategy {
Default
RLE
Filtered
Static
Huffman
}type DecoderBufStreamtype DecoderStreamtype EncoderBufStreamtype EncoderStreampub(all) enum Format {
Raw
Zlib
}A small zlib/DEFLATE implementation in MoonBit (ported from yazi).