# memorystream

> This is lightweight memory stream module for node.js.

Latest version **0.3.1** (published 2015-03-04) · 0 weekly downloads

## Install

```sh
npm install memorystream
pnpm add memorystream
yarn add memorystream
bun add memorystream
```

## Health

**Score 18/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2015-03-04 |
| First published | 2011-08-27 |
| Weekly downloads | 0 |
| TypeScript types | separate (@types/memorystream) |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 84 |
| Author | Dmitry Nizovtsev |
| Maintainers | jsbizon |
| Keywords | memory, test, stream, tools, streams, buffer |

## Links

- npm: https://www.npmjs.com/package/memorystream
- Repository: https://github.com/JSBizon/node-memorystream
- Issues: https://github.com/JSBizon/node-memorystream/issues
- npm.io page: https://npm.io/package/memorystream

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2015-03-04
- 0.3.0 — 2014-12-29
- 0.2.0 — 2012-06-26
- 0.1.1 — 2012-05-15
- 0.1.0 — 2012-02-07
- 0.0.5 — 2011-12-12
- 0.0.4 — 2011-09-01
- 0.0.3 — 2011-08-27
- 0.0.2 — 2011-08-27
- 0.0.1 — 2011-08-27

## README

[![Build Status](https://travis-ci.org/JSBizon/node-memorystream.svg?branch=master)](https://travis-ci.org/JSBizon/node-memorystream)

# 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](http://github.com/JSBizon/node-memorystream/wiki/API/ "Documentation").

---
_Source: https://npm.io/package/memorystream · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
