Buffer List collector with standard readable Buffer interface and streaming capabilities
npx @tessl/cli install tessl/npm-bl@6.1.0bl is a Node.js Buffer list collector, reader and streamer that provides a unified interface for managing collections of Buffer objects. It exposes a standard Buffer-readable API while operating efficiently across buffer boundaries, with streaming capabilities through a duplex stream interface.
npm install blconst BufferListStream = require('bl');
const { BufferListStream, BufferList } = require('bl');For TypeScript:
// CommonJS-style (recommended for Node.js)
import BufferListStream = require('bl');
import { BufferList, BufferListStream as BLS } = require('bl');
// ES module-style (with proper module resolution)
import * as BufferListStream from 'bl';
const { BufferList } = BufferListStream;const { BufferList } = require('bl');
// Create a buffer list and append data
const bl = new BufferList();
bl.append(Buffer.from('hello'));
bl.append(' world');
bl.append(Buffer.from([0x21])); // !
console.log(bl.toString()); // "hello world!"
console.log(bl.length); // 12
console.log(bl.slice(0, 5).toString()); // "hello"
// Use as a stream collector
const { BufferListStream } = require('bl');
const fs = require('fs');
fs.createReadStream('file.txt')
.pipe(BufferListStream((err, data) => {
if (err) throw err;
console.log(data.toString());
}));bl is built around two main components:
Both classes share the same API for buffer manipulation, with BufferListStream adding Node.js stream interface compatibility.
Core buffer collection functionality for managing multiple Buffer objects as a unified collection with efficient memory usage.
class BufferList {
constructor(initData?: BufferListAcceptedTypes);
append(buffer: BufferListAcceptedTypes): this;
prepend(buffer: BufferListAcceptedTypes): this;
get(index: number): number | undefined;
slice(start?: number, end?: number): Buffer;
length: number;
}
static BufferList.isBufferList(obj: unknown): boolean;Duplex stream implementation of BufferList for streaming data collection and emission with callback support.
class BufferListStream extends BufferList {
constructor(callback?: (err: Error | null, buffer: Buffer) => void);
// Inherits all BufferList methods plus stream methods
}
static BufferListStream.isBufferList(obj: unknown): boolean;type BufferListAcceptedTypes =
| Buffer
| BufferList
| Uint8Array
| BufferListAcceptedTypes[]
| string
| number;