https://github.com/dmitriym09/stream-storage
Simple duplex nodejs streams for cache large data in memory and files.
https://github.com/dmitriym09/stream-storage
buffer cache duplex js memory nodejs stream
Last synced: 2 months ago
JSON representation
Simple duplex nodejs streams for cache large data in memory and files.
- Host: GitHub
- URL: https://github.com/dmitriym09/stream-storage
- Owner: dmitriym09
- Created: 2019-08-09T09:11:38.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T18:24:34.000Z (over 3 years ago)
- Last Synced: 2026-01-01T07:27:09.344Z (6 months ago)
- Topics: buffer, cache, duplex, js, memory, nodejs, stream
- Language: JavaScript
- Homepage:
- Size: 212 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node stream storage


Simple duplex streams for cache large data in memory and files.
## Installing
```bash
npm install stream-storage
```
## Usage
```js
import { StreamStorage } from 'stream-storage';
const streamStorage = new StreamStorage();
// using ...
streamStorage.clear();
```
### stream-storage
**StreamStorage** extends the standard [stream.Duplex](https://nodejs.org/api/stream.html#stream_class_stream_duplex) interface. All writes data to this stream will accumulate in internal [Buffers](https://nodejs.org/api/buffer.html). Data exceeding the *maxMemorySize* of the size will be saved to a file.
You can change default options:
```js
const streamStorage = new StreamStorage({
maxMemorySize: (32 * 1024), // max memory size, bytes
tmpDir: '.', // temp dir for a file
pushMsec: 1, // pushed data interval, msec
chunkSize: (8 * 1024), // pushed data chunk size, bytes
});
```
For rereading data you can move current stream to new by `StreamStorage.move()`.
More using cases and examples you can see in [test](test/test.mjs).
## Contributors
- dmitriym09
Thanks to the [node-stream-buffer](https://github.com/samcday/node-stream-buffer) for inspiration!
## dev
### test
For run test:
```js
npm run test
```
## versions
- **0.0.1** - init
- **0.0.2**
- **0.0.3**
- **0.0.4**
- **0.0.5** - fix pause
- **1.0.0** - .mjs, impl StreamStorage.move()