wiithon.fst.serializer module

class wiithon.fst.serializer.FSTToBytes(fst_entries)[source]

Bases: object

Pre-computed, build-ready representation of a FST.

Unlike FST.write(), which simply serialises existing offsets, this class is designed for the builder where file data offsets are not known in advance. The string table is computed once at construction time

Parameters:

fst_entries (List[FSTNode])

get_total_file_count()[source]

Return the total number of FSTFile nodes in the tree

Return type:

int

callback_all_files(callback)[source]

Call the callback for every FSTFile in depth-first order.

Callback params:
  • path_parts: the directory path as a list of names

  • file_node: the FSTFile node itself so the caller can mutate offset and length directly

Parameters:

callback (Callable[[List[str], FSTFile], None]) – callback(path_parts, file_node)

Return type:

None

write_to(stream)[source]

Serialise the FST (raw nodes + string table) to stream at the current position.

File offsets are taken from the FSTFile nodes as they are at call time, so call this once as a placeholder (offsets=0), write the file data, then call it again with the updated offsets.

Parameters:

stream (BinaryIO | CryptPartWriter) – Writable binary stream

Return type:

None

byte_size()[source]

Return the total serialised byte size of this FST (nodes + string table)

Return type:

int