Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hubgit/input-stream
Read data from a CSV or NDJSON file to a stream
https://github.com/hubgit/input-stream
csv ndjson stream
Last synced: 12 days ago
JSON representation
Read data from a CSV or NDJSON file to a stream
- Host: GitHub
- URL: https://github.com/hubgit/input-stream
- Owner: hubgit
- Created: 2018-01-30T08:57:06.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-09T07:17:40.000Z (almost 3 years ago)
- Last Synced: 2025-01-10T07:15:40.232Z (20 days ago)
- Topics: csv, ndjson, stream
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/input-stream
- Size: 185 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# input-stream
## Install
`npm install --save input-stream`
or
`yarn add input-stream`
## Formats
The input stream functions as an async iterator, so each item can be awaited in a `for` loop.
### CSV
```js
const input = require('input-stream')('data/example.csv')for await (const item of input) {
console.log(item)
}
```Options provided as a second parameter will be passed through to [csv-parser](https://www.npmjs.com/package/csv-parser).
### TSV
```js
const input = require('input-stream')('data/example.tsv')for await (const item of input) {
console.log(item)
}
```Options provided as a second parameter will be passed through to [csv-parser](https://www.npmjs.com/package/csv-parser), apart from `separator`.
### NDJSON
```js
const input = require('input-stream')('data/example.ndjson')for await (const item of input) {
console.log(item)
}
```### XML
```js
const input = require('input-stream')('data/example.xml', {
element: 'foo'
})for await (const item of input) {
console.log(item)
}
```Options provided as a second parameter will be passed through to xml-stream, apart from `output`.
## Piping to an output stream
An example of piping the input stream directly to [output-stream](https://www.npmjs.com/package/output-stream), for conversion between formats.
```js
const input = require('input-stream')('data/example.csv')
const output = require('output-stream')('data/example.ndjson')input.pipe(output)
```