Registry / serialization / bufio
library0.0.0jsnpmunverified

Bufio is a JavaScript library providing low-level buffer and serialization utilities, primarily designed for Node.js environments. Its current and only stable version is 1.2.3, released in 2018. The library focuses on efficient binary data encoding and decoding, offering classes like `BufferWriter`, `BufferReader`, and an extensible `Struct` base class for defining custom binary data structures. It was originally developed as part of the bcoin-org ecosystem, often used in cryptocurrency and blockchain projects requiring precise control over binary data formats. The library's core differentiator is its explicit control over buffer manipulation and serialization patterns, which, while powerful, requires developers to manage byte lengths and encodings manually. It is not actively maintained, with its last update occurring in 2018.

npm install bufio
INSTALL
IMPORT
SIG · BUFIO
B
bufio
serializationjavascriptv0.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

bio
✓ const bio = require('bufio');
✗ import bio from 'bufio';
Bufio is primarily a CommonJS library. There is no official ESM entry point as of v1.2.3, so direct `import` statements will likely fail in pure ESM contexts.
BufferWriter (via bio.write)
✓ const bw = bio.write();
✗ import { write } from 'bufio';
`write` is a factory method on the main `bio` object, not a named export. It returns a `BufferWriter` instance.
BufferReader (via bio.read)
✓ const br = bio.read(buffer);
✗ import { read } from 'bufio';
`read` is a factory method on the main `bio` object, not a named export. It returns a `BufferReader` instance.
Struct
✓ class MyStruct extends bio.Struct {}
✗ import { Struct } from 'bufio';
`Struct` is a constructor property on the main `bio` object, not a named export. It serves as a base class for custom serialization schemas.

Demonstrates both basic buffer writer/reader usage and the creation of a custom serializable `Struct` class, including encoding and decoding to/from various formats.

const assert = require('assert'); const bio = require('bufio'); // Basic Usage: Write and Read const bw = bio.write(); bw.writeU64(100); bw.writeString('foo'); const data = bw.render(); const br = bio.read(data); assert.strictEqual(br.readU64(), 100); assert.strictEqual(br.readString(3), 'foo'); // Struct Usage: Define custom serializable objects class MyStruct extends bio.Struct { constructor() { super(); this.str = 'hello'; this.value = 0; } write(bw) { bw.writeVarString(this.str, 'ascii'); bw.writeU64(this.value); return this; } read(br) { this.str = br.readVarString('ascii'); this.value = br.readU64(); return this; } } const obj = new MyStruct(); obj.str = 'world'; obj.value = 12345; console.log('Original object:', obj); console.log('Encoded Buffer (Hex):', obj.toHex()); const decodedObj = MyStruct.fromHex(obj.toHex()); console.log('Decoded object:', decodedObj); assert.deepStrictEqual(obj, decodedObj);
Debug
Known issues
gotchaBufio is primarily a CommonJS library. Attempting to use `import` statements directly in a pure ESM project will result in errors like 'require is not defined' or 'bufio does not provide an export named X'.
fix
Use `const bio = require('bufio');` for all imports. If in an ESM module, consider a wrapper or a build step to handle CommonJS modules, or use dynamic import `import('bufio').then(bio => ...)`. Alternatively, for Node.js 12+, you might be able to use `createRequire` from `module`.
affects: >=1.0.0
breakingThe library is not actively maintained since its last update in 2018. This means it may not receive updates for security vulnerabilities, bug fixes, or compatibility with newer Node.js versions or JavaScript language features.
fix
Evaluate whether the unmaintained status poses a risk for your application, especially for security-critical operations involving low-level buffer manipulation. Consider auditing the code for known vulnerabilities or exploring more actively maintained alternatives if possible.
affects: >=1.0.0
gotchaBufio does not provide TypeScript declaration files (`.d.ts`). Developers using TypeScript will need to write their own declaration files or use `any` types, losing type safety.
fix
Create a `bufio.d.ts` file in your project or use a declaration merging pattern to provide type definitions for the `bufio` module. Example: `declare module 'bufio' { export = any; }` (less ideal) or more specific typings for `Writer`, `Reader`, and `Struct`.
affects: >=1.0.0
gotchaThis library assumes a deep understanding of binary serialization and buffer manipulation. Errors in specifying lengths, types, or endianness can lead to corrupted data or security vulnerabilities.
fix
Thoroughly test all serialization and deserialization routines. Ensure that byte order, string encodings, and numerical sizes are explicitly matched between writing and reading operations.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to import the CommonJS-only `bufio` library using an ESM `import` statement in an environment that does not support it, or in a file configured as an ES module.
fix
For Node.js projects, ensure the file using `bufio` is a CommonJS module (e.g., `.js` file without `"type": "module"` in `package.json`, or explicitly `.cjs`). Use `const bio = require('bufio');` to import the library.
TypeError: bio.write is not a function
Incorrectly attempting to destructure named exports (`import { write } from 'bufio';`) when `bufio` exports a single object or function as its default (and only) export in CommonJS.
fix
Import the entire module using `const bio = require('bufio');` and access `write` as a property: `const bw = bio.write();`.
TypeError: bio.Struct is not a constructor
Similar to `bio.write`, this error occurs if `Struct` is attempted to be imported as a named export or accessed incorrectly.
fix
After importing the entire module with `const bio = require('bufio');`, access `Struct` as a property: `class MyStruct extends bio.Struct {}`.
Upgrade
Version history
0.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
bufio — npm install bufio · libregistry