# spawn-to-readstream

> Converts spawn to a ReadStream, buffers the error and emits it

Latest version **0.1.3** (published 2014-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install spawn-to-readstream
pnpm add spawn-to-readstream
yarn add spawn-to-readstream
bun add spawn-to-readstream
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2014-05-21 |
| First published | 2013-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Alexandru Vladutu |
| Maintainers | alessioalex |
| Keywords | buffer-spawn-error, error, spawn, limit, spawn-error |

## Links

- npm: https://www.npmjs.com/package/spawn-to-readstream
- Repository: https://github.com/alessioalex/spawn-to-readstream
- Issues: https://github.com/alessioalex/spawn-to-readstream/issues
- npm.io page: https://npm.io/package/spawn-to-readstream

## Dependencies (2)

- [through2](https://npm.io/package/through2.md) ~0.4.1
- [limit-spawn](https://npm.io/package/limit-spawn.md) 0.0.3

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.1.3 (latest) — 2014-05-21
- 0.1.2 — 2014-05-21
- 0.1.1 — 2014-05-21
- 0.1.0 — 2013-08-02
- 0.0.1 — 2013-07-09

## README

# spawn-to-readstream

### Description

Make child process spawn behave like a read stream (buffer the error, don't emit end if error emitted).

### Installation

```bash
npm install spawn-to-readstream
```

### Examples

```js
var toReadStream = require('spawn-to-readstream'),
    spawn        = require('child_process').spawn;

toReadStream(spawn('ls', ['-lah'])).on('error', function(err) {
  throw err;
}).on('end', function() {
  console.log('~~~ DONE ~~~');
}).on('data', function(data) {
  console.log('ls data :::', data.toString());
});
```

Limiting the output of the steam

```js
var toReadStream = require('../index'),
    spawn        = require('child_process').spawn,
    limit, buf;

buf   = 0;
limit = 100 * 1024; // 100 Kb

// Note that it's a 'soft' limit, meaning the data you
// receive might be > 100 Kb, because the child process
// was stopped after receiving more than <LIMIT> bytes
toReadStream(spawn('cat', ['/dev/urandom']), limit)
  .on('error', function(err) {
    throw err;
  }).on('end', function(isLimited) {
    console.log('done, ' + buf + ' bytes received');
    if (isLimited) {
      console.log('child process was cut');
    }
  }).on('data', function(data) {
    buf += data.length;
  });
```

### Tests

```bash
npm test
```

## License

MIT

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