buffer-queue

WebJar for buffer-queue

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

buffer-queue
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

buffer-queue
WebJar for buffer-queue
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/jsantell/buffer-queue

Скачать buffer-queue

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/buffer-queue/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>buffer-queue</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/buffer-queue/
implementation 'org.webjars.npm:buffer-queue:1.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/buffer-queue/
implementation ("org.webjars.npm:buffer-queue:1.0.0")
'org.webjars.npm:buffer-queue:jar:1.0.0'
<dependency org="org.webjars.npm" name="buffer-queue" rev="1.0.0">
  <artifact name="buffer-queue" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='buffer-queue', version='1.0.0')
)
libraryDependencies += "org.webjars.npm" % "buffer-queue" % "1.0.0"
[org.webjars.npm/buffer-queue "1.0.0"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

buffer-queue

Build Status Build Status

A fast buffer store, for queueing up buffer chunks to later drain as a full buffer for streams. Faster than Buffer.concat on every chunk.

Install

npm install buffer-queue

Usage

Example of a transform stream that only writes downstream 1MB at a time, storing up buffers in the buffer store.

var Transform = require("stream").Transform;
var util = require("util");
var Store = require("buffer-queue");

/**
 * Transform stream that limits writes to 1MB at a time
 */
function ThrottleStream (limit) {
  this.limit = limit || 1024 * 1024;
  this.store = new Store();
  Transform.call(this);
}
util.inherits(ThrottleStream, Transform);

ThrottleStream.prototype._transform = function (chunk, enc, callback) {
  this.store.push(chunk);
  var data;

  // While we have more in our store than the limit, then push
  // out a chunk
  while (this.store.length() > this.limit && data = this.store.shift(this.limit)) {
    this.push(data);
  }
  callback();
};

ThrottleStream.prototype._flush = function (callback) {
  var data;
  while (data = this.store.shift(this.limit)) {
    this.push(data);
  }
  callback();
};

API

BufferStore()

Constructor for a buffer store.

store.push(buffer)

Pushes a buffer to the store.

store.shift(n)

Returns the first n bytes of the entire buffer store and removes from the store.

store.empty()

Empties the entire internal buffer store.

store.length()

Returns the length of the internal buffer store in bytes.

store.drain()

Empties and returns the internal buffer store. Use store.empty() if you are not interested in the return value.

Testing

npm test

License

MIT License, Copyright (c) 2015 Jordan Santell

Версии библиотеки

Версия
1.0.0