# str-to-stream

> Convert string into a readable stream.

Latest version **1.0.2** (published 2018-12-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install str-to-stream
pnpm add str-to-stream
yarn add str-to-stream
bun add str-to-stream
```

## 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 | 1.0.2 |
| Published | 2018-12-07 |
| First published | 2018-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 0 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Risan Bagja Pradana |
| Maintainers | risan |
| Keywords | string, stream |

## Links

- npm: https://www.npmjs.com/package/str-to-stream
- Repository: https://github.com/risan/str-to-stream
- Homepage: https://github.com/risan/str-to-stream#readme
- Issues: https://github.com/risan/str-to-stream/issues
- npm.io page: https://npm.io/package/str-to-stream

## 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

- 1.0.2 (latest) — 2018-12-07
- 1.0.1 — 2018-12-02
- 1.0.0 — 2018-11-26

## README

# String to Stream

[![Build Status](https://badgen.net/travis/risan/str-to-stream)](https://travis-ci.org/risan/str-to-stream)
[![Test Covarage](https://badgen.net/codecov/c/github/risan/str-to-stream)](https://codecov.io/gh/risan/str-to-stream)
[![Greenkeeper](https://badges.greenkeeper.io/risan/str-to-stream.svg)](https://greenkeeper.io)
[![Latest Version](https://badgen.net/npm/v/str-to-stream)](https://www.npmjs.com/package/str-to-stream)

Convert string into a readable stream.

## Installation

```bash
$ npm install str-to-stream
```

## Usage

Pipe a string into a writable stream:

```js
const strToStream = require("str-to-stream");

const stream = strToStream("hello world!");

stream.pipe(process.stdout);
```

Listen to `data` event:

```js
const strToStream = require("str-to-stream");

const stream = strToStream("hello world!");

stream.on("data", chunk => console.log(`Data received: ${chunk.toString()}`));

stream.on("end", () => console.log("All data have been received."));
```

## Recipes

### Set the Data Bytes Limit for Each Chunk

By default, each data chunk is limited to 16,384 bytes. You can override this by passing the `highWaterMark` option:

```js
const strToStream = require("str-to-stream");

const stream = strToStream("hello world!", {
  highWaterMark: 6
});

const chunks = [];

stream.on("data", chunk => chunks.push(chunk.toString()));

stream.on("end", () => console.log(chunks)); // ["hello ", "world!"]
```

### Emit Data in One Shot

To emit all string data in one shot, set the `objectMode` option to `true`. The `highWaterMark` option value won't have any effect.

```js
const strToStream = require("str-to-stream");

const stream = strToStream("a very long long string...", {
  highWaterMark: 6, // Won't have any effect.
  objectMode: true
});

stream.on("data", chunk => {
  console.log(chunk.toString()); // a very long long string...
});
```

### Write to a File

```js
const fs = require("fs");
const strToStream = require("str-to-stream");

const file = fs.createWriteStream("./hello.txt");

const stream = strToStream("hello world!");

stream.pipe(file);
```

## API

```js
strToStream(data, [{ highWaterMark, objectMode }])
```

### Parameters

* **`data`** (*`String`*): The string to convert to a readable stream.
* **`highWaterMark`** (optional *`Number`*): The maximum number of bytes for each chunk, default to `16384` (16kb).
* **`objectMode`** (optional *`Boolean`*): When it sets to `true`, the string `data` will be emitted in one shot ignoring the `highWaterMark` option. Default to `false`.

### Returns

It returns [`Readable` Stream](https://nodejs.org/api/stream.html#stream_readable_streams) instance.

## License

[MIT](https://github.com/risan/str-to-stream/blob/master/LICENSE) © [Risan Bagja Pradana](https://bagja.net)

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