mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-04-30 12:00:39 +00:00
8c7017a99d
- Update obioptions.Version from "Release 4.4.29" to "/v/ Release v5" - Update version.txt from 4.29 → .30 (automated by Makefile)
1.7 KiB
1.7 KiB
WriteFileChunk Function — Semantic Description
The WriteFileChunk function in the obiformats package implements a thread-safe, ordered chunk writer for streaming data to an io.WriteCloser. It accepts a destination writer and a flag indicating whether the writer should be closed upon completion.
-
Input:
writer: Anio.WriteCloser(e.g., file, buffer) to which data chunks are written.toBeClosed: Boolean flag specifying if the writer should be closed after all chunks are processed.
-
Core Behavior:
- Launches a goroutine that consumes
FileChunkitems from an unbuffered channel (chunk_channel). - Ensures strict sequential ordering of chunks by their
Orderfield (intended for reassembly after parallel or out-of-order processing). - If a chunk arrives in order (
chunk.Order == nextToPrint), it is immediately written. - Out-of-order chunks are buffered in a map (
toBePrinted) until their predecessor arrives.
- Launches a goroutine that consumes
-
Buffer Management:
- After writing an in-order chunk, the function checks for newly consecutive buffered chunks and writes them greedily (e.g., if order 2 arrives, it triggers writing of buffered orders 3,4,... as available).
-
Error Handling:
- Logs fatal errors on write failures or writer closure issues using
log.Fatalf.
- Logs fatal errors on write failures or writer closure issues using
-
Cleanup & Lifecycle:
- Closes the underlying writer if requested and unregisters a pipe registration (via
obiutils) to signal end-of-stream. - Returns the input channel, enabling external producers to stream
FileChunkstructs.
- Closes the underlying writer if requested and unregisters a pipe registration (via
-
Use Case:
Designed for robust, ordered reconstruction of large binary/data streams (e.g., sequencing reads) in OBITools4 pipelines, especially where parallel chunking and reassembly occur.