libtcspc.WriteBinaryStream¶
- final class libtcspc.WriteBinaryStream(stream, buffer_provider=None, write_granularity_bytes=65536)[source]¶
Bases:
NodeSink processor that writes raw bytes to a binary output stream.
Input is a
BucketEventof bytes; the contained bytes are written to the output stream. To write typed events, precede this processor withViewAsBytes(and usuallyBatch) to convert bucketed events to their in-memory bytes. This processor is a sink: it has no outputs.- Parameters:
stream (OutputStream) – The output stream to write to (for example a
BinaryFileOutputStream).buffer_provider (BucketSource or Param[PyBucketSource] or None) – Source of byte buckets used to coalesce writes. If
None, a defaultRecyclingBucketSourcefor bytes is used. A runtimeParamof typePyBucketSourcebinds a Python bucket source at execution time.write_granularity_bytes (int or Param[int]) – Minimum write size in bytes. Defaults to
65536. Larger writes have less per-byte overhead but may pollute CPU caches; try different powers of two and measure.
Notes
Events handled:
BucketEventof byte event type: write its bytes to the stream.All other event types: rejected at graph build time.
End of input: flush the stream. Raises an exception (corresponding to C++
input_output_error) on a stream write error.
See also
- tcspc::write_binary_stream()
The underlying C++ factory function.
ViewAsBytesView bucketed events as their in-memory bytes to feed this sink.
ReadBinaryStreamThe inverse: read events from a binary input stream.
write_events_to_binary_fileHigher-level convenience that accepts individual events and writes them to a binary file (batching and byte conversion handled internally).