or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

buffer-list-stream.mdbuffer-list.mdindex.md
tile.json

tessl/npm-bl

Buffer List collector with standard readable Buffer interface and streaming capabilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/bl@6.1.x

To install, run

npx @tessl/cli install tessl/npm-bl@6.1.0

index.mddocs/

bl (Buffer List)

bl 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.

Package Information

  • Package Name: bl
  • Package Type: npm
  • Language: JavaScript with TypeScript support
  • Installation: npm install bl

Core Imports

const 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;

Basic Usage

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());
  }));

Architecture

bl is built around two main components:

  • BufferList: Core buffer collection class providing Buffer-like API for managing multiple buffers as a unified collection
  • BufferListStream: Duplex stream extension of BufferList that adds streaming capabilities for reading and writing data

Both classes share the same API for buffer manipulation, with BufferListStream adding Node.js stream interface compatibility.

Capabilities

Buffer Collection

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;

Buffer Collection

Stream Interface

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;

Stream Interface

Types

type BufferListAcceptedTypes = 
  | Buffer 
  | BufferList 
  | Uint8Array 
  | BufferListAcceptedTypes[] 
  | string 
  | number;