Registry / http-networking / superagent-binary-parser

superagent-binary-parser

JSON →
library1.0.1jsnpmunverified

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-parser
INSTALL
IMPORT
SIG · SUPERAGENT-BINARY-
S
superagent-binary-parser
http-networkingjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

binaryParser
const binaryParser = require('superagent-binary-parser');
import binaryParser from 'superagent-binary-parser';
The package is CommonJS-only (published 2017) and does not natively support ES Modules. Using `import` syntax without a transpiler or ESM compatibility layer will result in an error.
superagent
const superagent = require('superagent');
import superagent from 'superagent';
While `superagent` itself has modern ESM support in newer versions, the usage pattern with `superagent-binary-parser` often implies a CommonJS context due to the plugin's age.

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.

const fs = require('fs'); const binaryParser = require('superagent-binary-parser'); const superagent = require('superagent'); // Use a public PDF for demonstration const pdfUrl = 'https://www.africau.edu/images/default/sample.pdf'; const outputPath = './downloaded.pdf'; console.log(`Attempting to download ${pdfUrl} and save as ${outputPath}...`); superagent.get(pdfUrl) .parse(binaryParser) .buffer(true) // Ensure response is buffered as a Buffer .end(function(err, resp) { if (err) { console.error('Download error:', err.message); return; } if (!resp.body || !(resp.body instanceof Buffer)) { console.error('Response body is not a Buffer.'); return; } fs.writeFileSync(outputPath, resp.body); console.log(`Successfully downloaded PDF to ${outputPath}. File size: ${resp.body.length} bytes`); });
Debug
Known issues
gotchaThis package has not been updated in many years (last published 2017) and may not be fully compatible with recent major versions of `superagent` or modern JavaScript environments (e.g., native ES Modules). `superagent` itself has undergone several breaking changes regarding `.parse()` and `.end()` behavior over the years.
fix
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.
affects: >=1.0.1
deprecatedThe package exclusively uses CommonJS `require()` syntax. Attempting to import it using ES Module `import` syntax in a pure ESM environment without a transpilation step or Node.js's compatibility layers (like `createRequire`) will lead to runtime errors.
fix
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.
affects: 1.0.1
gotchaThe `buffer()` method on the `superagent` request is crucial when using this parser in Node.js to ensure the response is collected into a `Buffer`. Without `buffer(true)`, `resp.body` might be empty or incomplete if `superagent` doesn't buffer by default for the given content type, especially when handling unbuffered streams.
fix
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`.
affects: >=1.0.1
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require('superagent-binary-parser')` within an ES Module (type: 'module' in package.json) environment.
fix
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');`
TypeError: superagent.get(...).parse is not a function
This error is unlikely directly from `superagent-binary-parser` itself, but could indicate `superagent` version incompatibility or improper `superagent` setup if `.parse` was renamed or removed in a breaking `superagent` change you're using.
fix
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.
Error: resp.body is not a Buffer or is empty after parsing binary data.
The `superagent` request pipeline did not correctly buffer the response into a `Buffer` before `superagent-binary-parser` could process it, or the response itself was empty.
fix
Always include `.buffer(true)` in your `superagent` request chain, e.g., `superagent.get(url).parse(binaryParser).buffer(true).end(...)`.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
superagentrequiredThis package is a plugin for `superagent` and requires it to function. It is expected to be installed by the user, as `superagent-binary-parser` itself lists 0 direct dependencies on npm.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
superagent-binary-parser — npm install superagent-binary-parser · libregistry