The `superagent-binary-parser` package is a lightweight plugin designed for the `superagent` HTTP client library, specifically enabling the parsing of binary response streams (e.g., PDF, ZIP files, images) directly into a Node.js `Buffer`. Instead of `superagent` attempting to interpret the response body as text or JSON, this plugin ensures the raw binary data is available in `resp.body`. The package's current stable version is 1.0.1, which was last published in March 2017. With its last commit observed approximately four years ago, it follows a maintenance-only or effectively abandoned release cadence. Its key differentiator is providing a straightforward, dedicated parsing function to integrate with `superagent`'s `.parse()` method, addressing the need for robust binary data handling beyond `superagent`'s default text-based parsers.
npm install superagent-binary-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `superagent-binary-parser` to download a PDF file, ensuring the response body is treated as a Node.js `Buffer` and then saved to the local filesystem. It highlights the `.parse(binaryParser)` and `.buffer(true)` methods.
Always test compatibility with your specific `superagent` version. For new projects, consider `superagent`'s native `.responseType('blob')` (in browser) or `.buffer(true)` with custom parsing logic (in Node.js), or a more actively maintained HTTP client library.Ensure your project is configured for CommonJS, use a bundler (Webpack, Rollup) that handles CJS-to-ESM conversion, or use Node.js's `createRequire` in ESM modules if strictly necessary.
Explicitly call `.buffer(true)` on your `superagent` request chain when using `superagent-binary-parser` to guarantee the full binary response is available as a `Buffer` in `resp.body`.
Either switch your module to CommonJS (`type: 'commonjs'`), use a bundler, or dynamically import CommonJS modules in ESM using `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const binaryParser = require('superagent-binary-parser');`Verify your `superagent` version and consult its changelog. Ensure `superagent` is correctly imported and that `superagent-binary-parser` is applied to a valid `superagent` request instance.
Always include `.buffer(true)` in your `superagent` request chain, e.g., `superagent.get(url).parse(binaryParser).buffer(true).end(...)`.