# stream-spigot

> A readable stream generator, useful for testing or converting simple functions into Readable streams.

Latest version **3.0.6** (published 2017-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-spigot
pnpm add stream-spigot
yarn add stream-spigot
bun add stream-spigot
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.6 |
| Published | 2017-03-28 |
| First published | 2013-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Bryce B. Baril |
| Maintainers | bryce |
| Keywords | streams2, testing, readable |

## Links

- npm: https://www.npmjs.com/package/stream-spigot
- Repository: https://github.com/brycebaril/node-stream-spigot
- Homepage: https://github.com/brycebaril/node-stream-spigot#readme
- Issues: https://github.com/brycebaril/node-stream-spigot/issues
- npm.io page: https://npm.io/package/stream-spigot

## Dependencies (2)

- [xtend](https://npm.io/package/xtend.md) ~4.0.0
- [readable-stream](https://npm.io/package/readable-stream.md) ~2.2.6

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 3.0.6 (latest) — 2017-03-28
- 3.0.5 — 2015-01-23
- 3.0.4 — 2014-06-04
- 3.0.3 — 2014-01-10
- 3.0.2 — 2013-12-18
- 3.0.1 — 2013-10-26
- 3.0.0 — 2013-10-16
- 2.1.2 — 2013-09-21
- 2.1.1 — 2013-08-14
- 2.1.0 — 2013-08-14
- 2.0.0 — 2013-07-21
- 1.0.0 — 2013-07-04

## README

Stream Spigot
=============

[![NPM](https://nodei.co/npm/stream-spigot.png)](https://nodei.co/npm/stream-spigot/)

[![david-dm](https://david-dm.org/brycebaril/node-stream-spigot.png)](https://david-dm.org/brycebaril/node-stream-spigot/)
[![david-dm](https://david-dm.org/brycebaril/node-stream-spigot/dev-status.png)](https://david-dm.org/brycebaril/node-stream-spigot#info=devDependencies/)


A generator for (streams2) Readable streams, useful for testing or converting simple lazy functions into Readable streams, or just creating Readable streams without all the boilerplate.

```javascript
var spigot = require("stream-spigot")

spigot.array(["ABCDEFG"]).pipe(process.stdout)
// ABCDEFG

spigot.array(["ABC", "DEF", "G"]).pipe(process.stdout)
// same as: (short form)
spigot(["ABC", "DEF", "G"]).pipe(process.stdout)
// ABCDEFG


// Create a stream out of a synchronous generator:
var count = 0
function gen() {
  if (count++ < 5) {
    return {val: count}
  }
}

spigot.sync({objectMode: true}, gen).pipe(...)
/*
{val: 1}
{val: 2}
{val: 3}
{val: 4}
{val: 5}
*/


// Create a more traditional Readable stream:
var source = spigot({objectMode: true}, function () {
  var self = this
  iterator.next(function (err, value) {
    if (err) return self.emit("error", err)
    self.push(value)
  })
})

source.pipe(...)

```

Usage
=====

spigot([options,] _read)
---

Create a Readable stream instance with the specified _read method. Your _read method should follow the normal [stream.Readable _read](http://nodejs.org/api/stream.html#stream_readable_read_size_1) syntax. (I.e. it should call `this.push(chunk)`)

spigot([options, ], array)
---

Create a Readable stream instance that will emit each member of the specified array until it is consumed. Creates a copy of the given array and consumes that -- if this will cause memory issues, consider implementing your own _read function to consume your array.

var Spigot = spigot.ctor([options,], _read)
---

Same as the above except provides a constructor for your Readable class. You can then create instances by using either `var source = new Spigot()` or `var source = Spigot()`.

var Spigot = spigot.ctor([options,], array)
---

Same as the above except provides a constructor for your Readable class. You can then create instances by using either `var source = new Spigot()` or `var source = Spigot()`.

spigot.array([options, ], array)
---

A manual version of the above to specify an array.


spigot.sync([options,] fn)
------------------------

Create a readable instance providing a synchronous generator function. It will internally wrap your synchronous function as an async function.

Options
-------

Accepts standard [readable-stream](http://npmjs.org/api/stream.html) options.

LICENSE
=======

MIT

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