{"id":18939,"library":"xresilient","title":"xresilient","description":"Builds regenerative, resumable Node.js readable streams that automatically retry on failure. Version 0.8.2 – stable, with TypeScript definitions included. Unlike manual retry logic or generic stream wrappers, xresilient tracks bytes read and supports range headers for resumable HTTP downloads. The stream can retry a user-supplied generator function a configurable number of times (default 5), emitting 'retry' and 'error' events. It extends stream.ReadableOptions, allowing custom destroyer functions and seamless integration with Node's stream pipeline. Suitable for fetching large files over unreliable networks.","status":"active","version":"0.8.2","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/miraclx/xresilient","tags":["javascript","typescript"],"install":[{"cmd":"npm install xresilient","lang":"bash","label":"npm"},{"cmd":"yarn add xresilient","lang":"bash","label":"yarn"},{"cmd":"pnpm add xresilient","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM default export – in CommonJS, require returns the default export directly, no .default needed.","wrong":"const xresilient = require('xresilient').default","symbol":"default","correct":"import xresilient from 'xresilient'"},{"note":"Named export for the stream class, useful for type checking or extending.","wrong":"const ResilientStream = require('xresilient').ResilientStream","symbol":"ResilientStream","correct":"import { ResilientStream } from 'xresilient'"},{"note":"CJS: require returns the default export directly, not a named export.","wrong":"const { xresilient } = require('xresilient')","symbol":"xresilient","correct":"const xresilient = require('xresilient')"}],"quickstart":{"code":"import xresilient from 'xresilient';\nimport request from 'request';\nimport fs from 'fs';\n\nconst retriableStream = xresilient(\n  function returnStream({ bytesRead, retryCount }) {\n    console.log(`Retry #${retryCount}, bytes so far: ${bytesRead}`);\n    return request.get('https://example.com/file.bin', {\n      headers: { Range: `bytes=${bytesRead}-` },\n    });\n  },\n  { retries: 3 }\n);\n\nretriableStream.pipe(fs.createWriteStream('file.bin'));\n\nretriableStream.on('retry', (slice) => {\n  console.log('Retrying...', slice);\n});\n\nretriableStream.on('error', (err) => {\n  console.error('Failed after retries:', err.message);\n});","lang":"typescript","description":"Creates a resumable stream that re-fetches a file with Range header on error, piping to disk."},"warnings":[{"fix":"Ensure fn always returns a valid, non-ended Readable stream unless you intend to end the resilient stream.","message":"The generator function must return a Readable stream; returning a destroyed or ended stream triggers retries or ends the resilient stream.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Listen to the 'retry' event to be notified of errors during retries, or check retryCount in the generator.","message":"The 'error' event is only emitted after all retries are exhausted. Early errors do not surface directly.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Wrap the stream to convert 'close' into 'error' if needed, or rely only on 'error' events.","message":"If the underlying stream emits a 'close' event prematurely, the retry logic may not trigger because it's not an 'error' event.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use const xresilient = require('xresilient').default instead of require('xresilient').","cause":"CommonJS require returns an object with default property in some bundlers.","error":"TypeError: xresilient is not a function"},{"fix":"Ensure the generator creates a new stream each invocation, and avoid reusing destroyed streams.","cause":"The underlying stream was destroyed but the generator function returned a stale stream.","error":"Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed"},{"fix":"Add `retriableStream.on('error', ...)` to handle final errors.","cause":"No error listener attached; errors after retries are exhausted propagate unhandled.","error":"Unhandled 'error' event in xresilient stream"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}