@alexjeffburke/bufferedstream

中文文档
1.6.1发布于 2018/12/17CommonJS零依赖近 30 天下载 7309

A stream class for node that reliably buffers until next tick

原始使用文档
文档目录5 节
  1. Rationale
  2. Installation
  3. Usage
  4. Tests
  5. License

build status

BufferedStream is a reliable base class for streams in node programs that buffers data until the next tick of the event loop.

Rationale

The details of streams are still being worked out in node core. As of this writing there are several different types of streams in node, including some objects that do not actually inherit from Stream. The goal of this library is to iron out the differences between the various stream-like objects and give user code a reliable, documented API they can use now. If the situation ever improves in node core (which we all hope it will) this code may become obsolete.

Installation

Using npm:

$ npm install bufferedstream

Usage

The key feature of this class is that anything you write to the stream in the current tick of the event loop is buffered until the next tick. This allows you to register event handlers, pause the stream, etc. reliably without losing any data.

var BufferedStream = require('bufferedstream');

var stream = new BufferedStream;
stream.write('Hello ');
stream.pause();

setTimeout(function () {
  stream.write('IHdvcmxkLg==', 'base64');
  stream.resume();
  stream.on('data', function (chunk) {
    console.log(chunk.toString()); // Hello world.
  });
}, 10);

The BufferedStream constructor may also accept a "source" which may be another stream that will be piped directly through to this stream or a string. This is useful for wrapping various stream-like objects and normalizing their behavior across implementations.

Please see the source code for more information. The module is small enough (and well-documented) that it should be easy to digest in a quick skim.

Tests

Run the tests with mocha:

$ mocha test

License

Copyright 2012 Michael Jackson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

版本与发布记录

@alexjeffburke/bufferedstream 共发布 1 个版本,首次发布于 2018/12/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.6.1latest2018/12/177 年前

关于 @alexjeffburke/bufferedstream 的常见问题

@alexjeffburke/bufferedstream 是什么?

A stream class for node that reliably buffers until next tick

如何安装 @alexjeffburke/bufferedstream?

在项目目录运行 npm install @alexjeffburke/bufferedstream,或使用 pnpm add / yarn add / bun add。

@alexjeffburke/bufferedstream 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/alexjeffburke__bufferedstream 是否存在。

@alexjeffburke/bufferedstream 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@alexjeffburke/bufferedstream 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=0.4.7。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@alexjeffburke/bufferedstream 可以商用吗?

@alexjeffburke/bufferedstream 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@alexjeffburke/bufferedstream 的下载量有多少?

根据 npm 官方下载统计,@alexjeffburke/bufferedstream 在 2026/10/06 – 2026/11/04 这 30 天内被下载 7,309 次,日均约 244 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alexjeffburke/bufferedstream 还在维护吗?

最新版本 1.6.1 发布于 2018/12/17(7 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/12/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。