0.3.1 • Published 9 years ago

memorystream v0.3.1

Weekly downloads
2,134,356
License
-
Repository
github
Last release
9 years ago

Build Status

Introduction

node-memorystream - this module allow create streams in memory. It can be used for emulating file streams, filtering/mutating data between one stream and another, buffering incoming data, being the gap between two data/network streams of variable rates, etc. MemoryStream support read/write states or only read state or only write state. The API is meant to follow node's Stream implementation. Module supports streams for node > 0.10 now.

Original module is here git://github.com/ollym/memstream.git was remade and improved.

Installation

If you have npm installed, you can simply type:

npm install memorystream

Or you can clone this repository using the git command:

git clone git://github.com/JSBizon/node-memorystream.git

Usage

Some examples how to use memorystream module.

Basic I/O Operation

In this example I illustrate the basic I/O operations of the memory stream.

var MemoryStream = require('memorystream');
var memStream = new MemoryStream(['Hello',' ']);

var data = '';
memStream.on('data', function(chunk) {
	data += chunk.toString();
});

memStream.write('World');

memStream.on('end', function() {
	// outputs 'Hello World!'
	console.log(data);
});
memStream.end('!');

Piping

In this example I'm piping all data from the memory stream to the process's stdout stream.

var MemoryStream = require('memorystream');
var memStream = new MemoryStream();
memStream.pipe(process.stdout, { end: false });

memStream.write('Hello World!');

In this example I'm piping all data from the response stream to the memory stream.

var http = require('http'),
	MemoryStream = require('memorystream');

var options = {
	host: 'google.com'
};
var memStream = new MemoryStream(null, {
	readable : false
});

var req = http.get(options, function(res) {
	res.pipe(memStream);
	res.on('end', function() {
		console.log(memStream.toString());
	});
});

Delayed Response

In the example below, we first pause the stream before writing the data to it. The stream is then resumed after 1 second, and the data is written to the console.

var MemoryStream = require('memorystream');

var memStream = new MemoryStream('Hello');
var data = '';
memStream.on('data', function(chunk) {
	data += chunk;
});

memStream.pause();
memStream.write('World!');

setTimeout(function() {
	memStream.resume();
}, 1000);

Documentation

The memory stream adopts all the same methods and events as node's Stream implementation. Documentation is available here.

npm-run-alldocker-api-node@budibase/server@inevix/grunt-webfontgrunt-webfont-patchedgrunt-webfontixix-grunt-webfont@swarnavl/one-element-testpileonidashboardtxttospeechfp-operator8base@loophole-labs/parasite@infinitebrahmanuniverse/nolb-memopea-bootstraap@everything-registry/sub-chunk-2154p149-tablewebvimwebvim-test@olympfin/olymp-swap-lib@object-studio/react-native-webgrunt-m2webfontgrunt-concurrent-pinterestgrunt-glitch@microsoft.azure/console@metis.io/solc@minowara/h265ize@nirin100/quadratic-protocol@nirin100/quadratic-sdkgitboard-cli-blessed-contrib@nodeberry/solidity-payment-processorimago-azure-storageimago-azure-blobsipl@safely-project/safely-tsgrunt-webfontgrunt-webfont-node-twelvegrunt-webfont-plusgrunt-webfont-v2grunt-webfont2grunt-webfont4fbhyinsit-server@pzzh/solc@qiwi/npm-run-all@patched/grunt-webfonthardhat-teaplughardhat-teaxyzhuydeptrai_contrib@shyftnetwork/shyft_solc@satrianak/hardhat-teaxyzjerusalem@pinf-it/inf@skedulr/nebula-ui-library@sat-utils/api-lib@pres/components-visual@prageeths/grunt-webfont@trfl/solc-compilejusto-plugin-pouchdb@thismr/bitmindtest-core@tidepool/vizkrzkaczor-solc@bespoken-api/shared@bespoken-sdk/nlp@bespoken-sdk/nlp-sdkbarista-core@bifproject/solc-bifneural_compressor_ext_lab_customizedneural_compressor_ext_lab_customized_2blazoblessed-contribblessed-contrib-neoblessed-terminalng1-serverneo-blessed-contrib@budibase/pro@blessed/blessed-contribblueskybluesky-litebone-cli-proxybone-proxyaspect-soliditymxt-command-webfontmysolcbagels-solc-jsjsdoc-json-live@xswap/v2-core@xgm/contract-librarynpm-solcnpm-run-all-v2npm-run-all2nsyncntnpm2-solcnpm1-solc@cybermega/flutter-resource-manager-rs@dadi/loggermongo-backup-to-s3aoe2-campaign-parserantrax8base-cli
0.3.1

9 years ago

0.3.0

9 years ago

0.2.0

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago

0.0.5

12 years ago

0.0.4

13 years ago

0.0.3

13 years ago

0.0.2

13 years ago

0.0.1

13 years ago