# vv-filestream

> write to file stream

Latest version **0.2.0** (published 2022-01-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install vv-filestream
pnpm add vv-filestream
yarn add vv-filestream
bun add vv-filestream
```

## 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.2.0 |
| Published | 2022-01-14 |
| First published | 2021-09-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 30.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Vitalii Vasilev |
| Maintainers | vasilev.v.vitalii |

## Links

- npm: https://www.npmjs.com/package/vv-filestream
- Repository: https://github.com/VasilevVitalii/vv-filestream
- Homepage: https://github.com/VasilevVitalii/vv-filestream#readme
- Issues: https://github.com/VasilevVitalii/vv-filestream/issues
- npm.io page: https://npm.io/package/vv-filestream

## Dependencies (1)

- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0

## Recent versions

- 0.2.0 (latest) — 2022-01-14
- 0.1.3 — 2022-01-13
- 0.1.2 — 2021-11-02
- 0.1.1 — 2021-10-19
- 0.1.0 — 2021-10-12
- 0.0.11 — 2021-10-06
- 0.0.10 — 2021-10-06
- 0.0.9 — 2021-10-06
- 0.0.8 — 2021-10-06
- 0.0.7 — 2021-10-06
- 0.0.6 — 2021-10-01
- 0.0.5 — 2021-10-01
- 0.0.4 — 2021-09-28
- 0.0.3 — 2021-09-28
- 0.0.2 — 2021-09-28
- … 1 more at https://npm.io/package/vv-filestream/versions

## README

# For NodeJS, custom WriteStream, based on standard fs.WriteStream.
## Features
1. Parallel writing multiple files (with once callback after the end of recording all files)
2. Ability to write JSON through the stream (see example)
## License
**MIT**
## Install
```
npm i vv-filestream
```
## Example
Writing two files. Each file is written in two chunks. First file has bad name, second file has good name.
### code
```javascript
const path = require('path')
const fs = require('fs')
const fileNameBad = 'a:/bad.json'
const fileNameGood = path.join(__dirname, 'good.json')
const data1 = [{aaaa: 1},{aaaa: 2},{aaaa: 3}]
const data2 = [{aaaa: 1, bbbb: 1},{aaaa: 2, bbbb: 2},{aaaa: 3, bbbb: 3},{aaaa: 4, bbbb: 4},{aaaa: 5, bbbb: 5}]
const vvfs = require('vv-filestream').Create({prefix: '[\n', suffix: '{}\n]'})
vvfs.onClose(result => {
    result.forEach(f => {
        console.log(`file   ${f.fullFileName}`)
        if (f.error) {
            console.log(`ERROR   ${f.error.message}`)
        } else {
            console.log('DATA')
            console.log(JSON.parse(fs.readFileSync(f.fullFileName, 'utf8')))
        }
    })
})
vvfs.write({fullFileName: fileNameBad, data: data1.slice(0, 2)})
vvfs.write({fullFileName: fileNameGood, data: data2.slice(0, 2)})
vvfs.write({fullFileName: fileNameBad, data: data1.slice(2, 5)})
vvfs.write({fullFileName: fileNameGood, data: data2.slice(2, 5)})
vvfs.close()
```
### note for result
1. result in vvfs.onClose - array:
```
[
    {fullFileName: 'a:/bad.json', error: Error: ENOENT: no such file or directory, open 'a:\\bad.json'}
    {fullFileName: ' ...  good.json', error: undefined}
]
```
2. file **good.json** has content (last empty object used to escape the comma after the previous line):
```
[
{"aaaa":1,"bbbb":2},
{"aaaa":2,"bbbb":2},
{"aaaa":3,"bbbb":3},
{"aaaa":4,"bbbb":4},
{"aaaa":5,"bbbb":5},
{}
]
```

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