# concurrent-streams

> Safe concurrent streams for reading and writing file

Latest version **0.0.1-dev** (published 2019-02-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install concurrent-streams
pnpm add concurrent-streams
yarn add concurrent-streams
bun add concurrent-streams
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-dev |
| Published | 2019-02-09 |
| First published | 2019-02-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 2 |
| Unpacked size | 28.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Muhamad Visat Sutarno |
| Maintainers | mvisat |
| Keywords | concurrent, streams |

## Links

- npm: https://www.npmjs.com/package/concurrent-streams
- Repository: https://github.com/mvisat/concurrent-streams
- Homepage: https://github.com/mvisat/concurrent-streams#readme
- Issues: https://github.com/mvisat/concurrent-streams/issues
- npm.io page: https://npm.io/package/concurrent-streams

## Dependencies (2)

- [emittery](https://npm.io/package/emittery.md) ^0.4.1
- [async-rwlock](https://npm.io/package/async-rwlock.md) ^1.1.1

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

- 0.0.1-dev (latest) — 2019-02-09

## README

# concurrent-streams

[![Build Status](https://travis-ci.org/mvisat/concurrent-streams.svg?branch=master)](https://travis-ci.org/mvisat/concurrent-streams)
[![codecov](https://codecov.io/gh/mvisat/concurrent-streams/branch/master/graph/badge.svg)](https://codecov.io/gh/mvisat/concurrent-streams)

Node.js safe multiple concurrent readable and writable streams from the same file.

## Install
```
$ yarn add concurrent-streams
```

## Quick Usage
```js
// TODO
```

## API

### `new ConcurrentStream(path, [options])`
- `path: string`
- `options?: StreamOptions`
    - `flags?: string` **Default:** `'r+'`
    - `fd?: number` **Default:** `undefined`
    - `mode?: number` **Default:** `0o666`
    - `autoClose?: boolean` **Default:** `true`
- Returns: instance of `ConcurrentStream`.

`flags` mode when opening a file. See [file system flags](https://nodejs.org/api/fs.html#fs_file_system_flags).

`path` will be ignored if `fd` is set, and no `open` event will be emitted.

`mode` sets the file permission if the file was created.

If `autoClose` is `true`, the file descriptor will be closed if no `ReadStream` or `WriteStream` referencing it. If `autoClose` is `false` it is the application's responsibility to close it and make sure there are no leak.

### `createReadStream([options])`
- `options?: ReadStreamOptions`
    - `encoding?: string` **Default:** `'utf8'`
    - `start?: number` **Default:** `0`
    - `end?: number` **Default:** `Infinity`
    - `highWaterMark` **Default:** `128 * 1024`
- Returns: instance of `ReadStream`, extending [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable).

`encoding` can be any one of those accepted by `Buffer`.

`start` and `end` can be used to read a range of bytes from the file. Both `start` and `end` is **inclusive** and start counting at 0.

`highWaterMark` is for readable stream high water mark.

### `createWriteStream([options])`
- `options?: ReadStreamOptions`
    - `encoding?: string` **Default:** `'utf8'`
    - `start?: number` **Default:** `0`
- Returns: instance of `WriteStream`, extending [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable).

`encoding` can be any one of those accepted by `Buffer`.

`start` can be used to write data at some position past beginning of the file.

## Class: `ConcurrentStream`

### Event: `'open'`
- `fd: number` file descriptor used.

Emitted when file descriptor has been opened.

### Event: `'close'`

Emitted when file descriptor has been closed.

### Event: `'error'`

Emitted when error occured.

## Class: `ReadStream`

### Event: `'read'`
- `bytesRead: number`, number of bytes read.

Emitted every time bytes has been succesfully read from file.

### Event: `'error'`
- `Error`

Emitten when error occured.

### Property: `readStream.position`
Current offset from beginning of file.

## Class: `WriteStream`

### Event: `'written'`
- `bytesWritten: number`, number of bytes written.

Emitted every time bytes has been succesfully written to file.

### Event: `'finish'`

Emitted when all data has been flushed to underlying system.

### Event: `'error'`
- `Error`

Emitten when error occured.

### Property: `writeStream.position`
Current offset from beginning of file.

## License
[MIT](LICENSE)

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