<commit_before># streamiterator
Converts ReadableStream into AsyncIterator.

### Using ###

With this module you can [iterate](https://github.com/tc39/proposal-async-iteration) over a nodejs stream (file, http response, etc) with a plain loop:

```js
import streamIterator from "streamiterator"
// or
// const streamIterator = require("streamiterator")

async function DoIt(stream) {
	for await (const value of streamIterator(stream)) {
		console.log(`Read: ${value}`)
	}
}
```

As of August, 2017 you need smth like either [babel](http://babeljs.io/) or [node.js 8.4.0 or higher](https://nodejs.org/) with `--harmony_async_iteration` switch to be able to use `for await` operator.

A bit of code with iterables can be seen in [tests](https://github.com/vadzim/streamiterator/blob/master/source/streamiterator.test.js).

It's possible to iterate without `for await`, though it is not so nice as using syntactic suger:

```js
import streamIterator from "streamiterator"

async function DoIt(stream) {
	for (
		let done, value, iterator = streamIterator(stream);
		{done, value} = await iterator.next(), !done;
	) {
		console.log(`Read: ${value}`)
	}
}
```

If the stream emits an error, it will be thrown while looping. Wrap your loop in `try..catch` to deal with it.

If eventually streams will support async iteration natively then this module will just redirect iteration to that native mechanism. No overhead will be added.

### Polyfill ###

But if you believe that writing `streamIterator(...)` everywhere is a bullshit, and in your world streams have to be iterable from the scratch right now, then you can import `streamiterator/polyfill` in the root of your project and iterate just on streams:

```js
import "streamiterator/polyfill"
import fs from "fs"

async function DoIt() {
	for await (const data of fs.createReadStream("./data.txt")) {
		console.log(data)
	}
}
```

Note that you don't need to import `streamiterator/polyfill` in every file of your project. Just in the `main.js` or similar.

### Contributing ###

__Please contribute!__
All contributions are greatly appreciated no matter how small or large the contribution is.
Whether it's a small grammar fix in the README, a huge bug fix, or just an issue report, you will be recognized as a 'Contributor' to this project.

Please, feel free to [open an issue](https://github.com/vadzim/streamiterator/issues) or email me to <EMAIL> if you have any question.
<commit_msg>example with lines in readme<commit_after># streamiterator
Converts ReadableStream into AsyncIterator.

### Using ###

With this module you can [iterate](https://github.com/tc39/proposal-async-iteration) over a nodejs stream (file, http response, etc) with a plain loop:

```js
import streamiterator from "streamiterator"
import split from "split"

async function DoIt() {
	// iterate over lines in a file
	for await (const line of streamiterator(
		fs.createReadStream("data.txt").pipe(split())
	)) {
		console.log(`Read: ${line}`)
	}
}
```

As of August, 2017 you need smth like either [babel](http://babeljs.io/) or [node.js 8.4.0 or higher](https://nodejs.org/) with `--harmony_async_iteration` switch to be able to use `for await` operator.

A bit of code with iterables can be seen in [tests](https://github.com/vadzim/streamiterator/blob/master/source/streamiterator.test.js).

It's possible to iterate without `for await`, though it is not so nice as using syntactic suger:

```js
import streamIterator from "streamiterator"

async function DoIt(stream) {
	for (
		let done, value, iterator = streamIterator(stream);
		{done, value} = await iterator.next(), !done;
	) {
		console.log(`Read: ${value}`)
	}
}
```

If the stream emits an error, it will be thrown while looping. Wrap your loop in `try..catch` to deal with it.

If eventually streams will support async iteration natively then this module will just redirect iteration to that native mechanism. No overhead will be added.

### Polyfill ###

But if you believe that writing `streamIterator(...)` everywhere is a bullshit, and in your world streams have to be iterable from the scratch right now, then you can import `streamiterator/polyfill` in the root of your project and iterate just on streams:

```js
import "streamiterator/polyfill"
import fs from "fs"

async function DoIt() {
	for await (const data of fs.createReadStream("./data.txt")) {
		console.log(data)
	}
}
```

Note that you don't need to import `streamiterator/polyfill` in every file of your project. Just in the `main.js` or similar.

### Contributing ###

__Please contribute!__
All contributions are greatly appreciated no matter how small or large the contribution is.
Whether it's a small grammar fix in the README, a huge bug fix, or just an issue report, you will be recognized as a 'Contributor' to this project.

Please, feel free to [open an issue](https://github.com/vadzim/streamiterator/issues) or email me to <EMAIL> if you have any question.

{'fraction_non_alphanumeric': 0.1037697608431293, 'fraction_numerical': 0.0036481556546412645, 'mean_word_length': 4.5078125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7331381', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1408, 'n_words': 623}