Registry / storage / stream-catcher

stream-catcher

JSON →
library1.0.5jsnpmunverified

A streaming wrapper around lru-cache that enables caching of readable streams and writing cached data to writable streams. Current version: 1.0.5 (unstable pre-1.0). Infrequently updated. Key differentiators: provides a simple streaming interface for caching, avoiding manual buffer management. Alternatives like `lru-cache` require manual serialization.

npm install stream-catcher
INSTALL
IMPORT
SIG · STREAM-CATCHER
S
stream-catcher
storagejavascriptv1.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StreamCatcher
import StreamCatcher from 'stream-catcher'
const StreamCatcher = require('stream-catcher').default;
Default export; CommonJS users can use `const StreamCatcher = require('stream-catcher')`.
StreamCatcher
const StreamCatcher = require('stream-catcher')
CommonJS pattern; exports a constructor function directly.
StreamCatcher
import StreamCatcher from 'stream-catcher'
import { StreamCatcher } from 'stream-catcher'
Named import is incorrect; it is a default export.

Shows how to create a streamCache, cache a readable stream, and write cached data to a writable stream.

import StreamCatcher from 'stream-catcher'; import { createReadStream, createWriteStream } from 'fs'; const cache = new StreamCatcher({ max: 1024 * 100, // 100KB length: (n) => n.length }); const key = 'example.txt'; const writePath = './output.txt'; const readPath = './input.txt'; // Write to cache (read from a source and cache) const readStream = createReadStream(readPath); cache.read(key, readStream); // Later: Read cached data to a writable stream const writeStream = createWriteStream(writePath); cache.write(key, writeStream, () => { console.log('Cache miss, populate cache first'); });
Debug
Known issues
breakingIn version 1.0.0, the constructor options changed to match lru-cache v2 options. Older versions used different option names.
fix
Update constructor options to align with lru-cache v2: use `max`, `length`, `maxAge` etc.
affects: <1.0.0
gotchaDo not mutate streams after passing to `read` or `write` methods; behavior is undefined.
fix
Ensure streams are used only once and not modified externally.
affects: >=0.0.0
gotchaThe `length` option function receives data chunks, not file sizes. Ensure it returns a numeric value appropriate for cache size calculation.
fix
Define `length` as a function that returns `(n) => n.length` for buffer-like data.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: streamCatcher.write is not a function
Using named import `{ StreamCatcher }` instead of default import.
fix
Use `import StreamCatcher from 'stream-catcher'` or `const StreamCatcher = require('stream-catcher')`.
Error: options.length is required
Missing `length` option in constructor when `max` is set.
fix
Provide a `length` option function, e.g., `length: (n) => n.length`.
Error: Cannot read property 'on' of undefined
Calling `read` with a non-stream argument (e.g., string path).
fix
Pass a valid readable stream object to `cache.read(key, stream)`.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
lru-cacherequiredCore caching logic is delegated to lru-cache.
Agent activity
30 hits · last 30 days
node
26
Amazon
1
OpenAI (training)
1
Resources
stream-catcher — npm install stream-catcher · libregistry