or run

npx @tessl/cli init
Log in

Version

Files

docs

index-management.mdindex.mdlisting.mdreading.mdremoval.mdutilities.mdverification.mdwriting.md
tile.json

task.mdevals/scenario-6/

Streaming Cache Writer

Create a helper that writes streaming content into a cache directory and reports the resulting integrity hash and byte size.

Capabilities

Streams data and reports integrity

  • Writes all chunks from a readable stream into the cache under a provided key and resolves with the computed integrity string and total bytes written. @test

Enforces expected size

  • When an expected byte length is provided, the write rejects if the streamed content size differs from that expectation. @test

Stores optional metadata

  • Metadata passed alongside the write is stored with the entry and can be retrieved when reading the cached item later. @test

Implementation

@generates

API

/**
 * Writes streaming content to a cache directory under a key.
 * @param {string} cachePath - Filesystem path to the cache root.
 * @param {string} key - Logical key identifying the entry.
 * @param {NodeJS.ReadableStream} source - Stream emitting Buffer or string chunks.
 * @param {object} [options]
 * @param {number} [options.expectedSize] - Fail if streamed bytes differ from this value.
 * @param {object} [options.metadata] - Optional JSON-serializable metadata to persist with the entry.
 * @returns {Promise<{ integrity: string, size: number }>} Resolves with integrity and byte length when the stream finishes successfully.
 */
export async function writeStream(cachePath, key, source, options);

Dependencies { .dependencies }

cacache { .dependency }

Provides streaming, content-addressable cache writes that emit integrity and size information.