Skip to main content

Module concat

Module concat 

Source
Expand description

Joins brotli streams that were compressed to be concatenated (-appendable for the first stream, -catable for the rest) into one stream.

A brotli stream is a sequence of bits, least significant bit first: a window size, then meta-blocks. It ends with an empty meta-block, which is just the two bits ISLAST and ISLASTEMPTY, followed by zero padding to the end of the byte. A catable stream starts with a meta-block whose header leaves the stream byte aligned (an uncompressed or metadata meta-block, or the stream’s final empty one), and it never refers back to data before itself.

So appending stream B to output A only takes changing a few bits where they meet:

  A:            ... | ISLAST ISLASTEMPTY | padding
  B:                                       window size | header | padding | aligned bytes ...
  A then B:     ... | header | padding | aligned bytes ...

A’s ISLAST/ISLASTEMPTY pair always lies in its last two bytes, so BroCatli holds the last two bytes of the output back (the tail) until it knows whether another stream follows, and copies everything else straight through.

StructsΒ§

BitReader πŸ”’
Reads bits from the buffered start of a stream.
BitWriter πŸ”’
Assembles bits into bytes, least significant bit first.
BroCatli
ByteBuf πŸ”’
A few buffered bytes.

EnumsΒ§

BroCatliResult
ParseError πŸ”’
Phase πŸ”’

ConstantsΒ§

FLAG_ANY_BYTES_EMITTED πŸ”’
FLAG_NEW_STREAM πŸ”’
FLAG_OPEN_TAIL πŸ”’
FLAG_TRUNCATED πŸ”’
FLAG_WRITE_SPLICE πŸ”’
NUM_STREAM_HEADER_BYTES πŸ”’
How many bytes of a new stream are buffered to find where it becomes byte aligned.

FunctionsΒ§

bit_range πŸ”’
The value of bits start..end of bytes, least significant bit first.
max_header_bytes πŸ”’
The most bytes of a new stream that are read before giving up on finding where it becomes byte aligned: 4, or 5 for a large window size. That fits an uncompressed first meta-block of up to 1 MiB (five length nibbles), or metadata with up to two length bytes.
remove_final_empty_metablock πŸ”’
Splits the final bytes of a stream into the bits before its closing ISLAST + ISLASTEMPTY pair, returning them with their count, or None if the bytes don’t end that way.