Relocate the ~6k-file docs tree from the repo root into plugins/document-navigator/docs/ so the plugin is self-contained and portable. docs/superpowers/ (specs and plans) stays at the repo root. Moved via cp+rm rather than git mv because directory rename() fails with EPERM on this WSL /mnt DrvFs mount; git rename-detection pairs the identical-content files at commit time. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
7.3 KiB
7.3 KiB
@suaveplan/streams-chunk-queue - Universal out-of-order chunk reconstitution: pluggable validation, decryption, rate limiting, storage, hooks, events, binary protocol, ReadableStream output
Universal out-of-order chunk reconstitution. Accepts chunks for a
file in any order and exposes a sequential
ReadableStream<Uint8Array> consumer surface, composed with pluggable
validation, decryption, rate limiting, persistent storage, lifecycle
hooks, a wildcard event bus, an efficient binary chunk-request
protocol, missing-chunk timeouts, and OpenTelemetry instrumentation.
Documentation tree
- binary-protocol — Produces the chunk-request wire frame consumed by
@suaveplan/drive-mesh,drive-transport-https, and any peer that n…- encoder — Produces the chunk-request wire frame consumed by
@suaveplan/drive-mesh,drive-transport-https, and any peer that n…
- encoder — Produces the chunk-request wire frame consumed by
- decryptor — Declares the
ChunkDecryptorstrategy interface and provides theNoopChunkDecryptordefault. Decryption is the third…- decryptor — Declares the
ChunkDecryptorstrategy interface and provides theNoopChunkDecryptordefault. Decryption is the third…
- decryptor — Declares the
- errors —
StreamsChunkQueueErroris the single typed error class raised by every public surface of `@suaveplan/streams-chunk-qu…- streams-chunk-queue-error —
StreamsChunkQueueErroris the single typed error class raised by every public surface of `@suaveplan/streams-chunk-qu…
- streams-chunk-queue-error —
- events — Implements the lightweight event bus that powers the queue's
addEventListener/removeEventListenersurface. The em…- events — Implements the lightweight event bus that powers the queue's
addEventListener/removeEventListenersurface. The em…
- events — Implements the lightweight event bus that powers the queue's
- hooks — Provides the helper functions that invoke the queue's eight lifecycle callbacks safely. The queue itself wires hook fir…
- hooks — Provides the helper functions that invoke the queue's eight lifecycle callbacks safely. The queue itself wires hook fir…
- pipeline — Houses the validation + decryption pipeline stages that the
StreamingChunkQueueruns on every received chunk. Extract… - storage-ops — Holds the storage-related guards used by
StreamingChunkQueue.loadChunkandloadAllChunks. Both methods need the sam… - streaming-chunk-queue —
StreamingChunkQueueis the public class that reconstitutes out-of-order chunked file transfers into a sequential `Rea… - rate-limiter — Normalises the
@suaveplan/rate-limiterTokenBucketAPI onto theChunkRateLimiterinterface used internall…- adapter — Normalises the
@suaveplan/rate-limiterTokenBucketAPI onto theChunkRateLimiterinterface used internall…
- adapter — Normalises the
- storage-adapter — Bridges
@suaveplan/storageAbstractStorageonto the queue'sChunkPersistercontract. Persistence enables resuming…- persister — Bridges
@suaveplan/storageAbstractStorageonto the queue'sChunkPersistercontract. Persistence enables resuming…
- persister — Bridges
- telemetry — Exposes the OpenTelemetry instruments that the
StreamingChunkQueuerecords during its lifecycle. Centralising instrum…- telemetry — Exposes the OpenTelemetry instruments that the
StreamingChunkQueuerecords during its lifecycle. Centralising instrum…
- telemetry — Exposes the OpenTelemetry instruments that the
- types — Declares the shared types consumed across every feature dir of
@suaveplan/streams-chunk-queue. Keeping them in one ty…- types — Declares the shared types consumed across every feature dir of
@suaveplan/streams-chunk-queue. Keeping them in one ty…
- types — Declares the shared types consumed across every feature dir of
- validator — Declares the
ChunkValidatorstrategy interface and provides theNoopChunkValidatordefault. Validation is the secon…- chunk-verifier-validator — Bridges the structural
ChunkVerifiershape from@suaveplan/packerinto the canonicalChunkValidatorstrategy. The… - validator — Declares the
ChunkValidatorstrategy interface and provides theNoopChunkValidatordefault. Validation is the secon…
- chunk-verifier-validator — Bridges the structural
Install
bun add @suaveplan/streams-chunk-queue
Quick start
import { StreamingChunkQueue } from "@suaveplan/streams-chunk-queue";
const queue = new StreamingChunkQueue({
fileId: 12345n,
totalChunks: 5n,
});
await queue.addChunk(2n, chunk2);
await queue.addChunk(0n, chunk0);
await queue.addChunk(1n, chunk1);
await queue.addChunk(3n, chunk3);
await queue.addChunk(4n, chunk4);
await queue.getStream().pipeTo(destination);
Modules
src/queue/streaming-chunk-queue.md— the publicStreamingChunkQueueclass.src/queue/pipeline.md— validation + decryption stages.src/queue/storage-ops.md— storage-side guards.src/validator/validator.md—ChunkValidatorstrategy +NoopChunkValidator.src/validator/chunk-verifier-validator.md— adapter for@suaveplan/packerChunkVerifier.src/decryptor/decryptor.md—ChunkDecryptorstrategy +NoopChunkDecryptor.src/rate-limiter/adapter.md—TokenBucketadapter onto the queue'sChunkRateLimiter.src/storage-adapter/persister.md—StorageChunkPersisteroverAbstractStorage.src/binary-protocol/encoder.md— chunk-request wire format.src/hooks/hooks.md— safe lifecycle-hook invocation.src/events/events.md— wildcard-capable event emitter.src/telemetry/telemetry.md— OTel counters + histogram.src/errors/streams-chunk-queue-error.md— error codes + class.src/types/types.md— shared types.
Features
- Out-of-order ingestion; duplicates silently ignored.
- Sequential
ReadableStream<Uint8Array>output. - Auto-start on first chunk.
- Pluggable validator + decryptor strategies with packer
ChunkVerifieradapter. - Non-destructive rate-limit backoff via
TokenBucketadapter. - Resumable transfers via
StorageChunkPersisteroverAbstractStorage. - Eight lifecycle hooks, wildcard event bus, 10 event types.
- Binary chunk-request protocol (12-byte header + bitmap).
- Configurable missing-chunk timeout (default 30 s).
- Progress events (0–100) + frozen
StreamingQueueStatussnapshot. - Bigint chunk identifiers (packer v2 u64).
StreamsChunkQueueErrorwith 8 stable codes.- OTel: 5 counters + 1 histogram.
License
MIT