Skip to main content
Version: 2.x

Brotli

The brotli module decompresses the Brotli format. It is built on the official Brotli Java decoder, which is pure Java. This module does not compress. To compress Brotli, use the Brotli4J module, which compresses and decompresses.

Add the module to your build.sbt:

libraryDependencies += "dev.zio" %% "zio-streams-compress-brotli" % "3.0.1"

BrotliDecompressorโ€‹

BrotliDecompressor is a Decompressor that reads the Brotli format:

import zio.compress._
import zio.stream._

val decompressed: ZStream[Any, Throwable, Byte] =
ZStream.fromFileName("file.br").via(BrotliDecompressor.decompress)

To read data that was compressed with a custom dictionary, pass the same dictionary to BrotliDecompressor.apply:

import zio.compress._

def dictionaryDecompressor(dictionary: Array[Byte]): BrotliDecompressor =
BrotliDecompressor(customDictionary = Some(dictionary))

Optionsโ€‹

OptionTypeDefault
customDictionaryOption[Array[Byte]]None (no dictionary)
chunkSizeInt4 KiB (ZStream.DefaultChunkSize)

The chunkSize is the largest chunk emitted by the output stream.

Notesโ€‹

  • The decompressor's error type is Throwable. Input that is not valid Brotli fails the stream.
  • This module cannot produce Brotli data. Use Brotli4JCompressor for that.

ZIO Chat

๐ŸŒŸ Greetings from ZIO Chat! ๐ŸŒŸ Have questions about ZIO? Look no further! I'm here to be your ZIO guru. Whether you're a seasoned pro or just starting out, I've got answers tailored just for you. Fire away with your ZIO queries, and I'll hit you back with the best insights I've got. Let's dive into the world of ZIO together!