https://github.com/nowsecure/disk-buffer
Disk buffer as a writable stream
https://github.com/nowsecure/disk-buffer
Last synced: 4 months ago
JSON representation
Disk buffer as a writable stream
- Host: GitHub
- URL: https://github.com/nowsecure/disk-buffer
- Owner: nowsecure
- Created: 2015-03-26T13:56:13.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-03-30T15:55:16.000Z (almost 11 years ago)
- Last Synced: 2025-08-27T20:15:09.667Z (5 months ago)
- Language: JavaScript
- Size: 109 KB
- Stars: 8
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# disk-buffer
Disk buffer as a writable stream, which after `n` bytes written and/or `m` writes finishes the file, emits an event and starts writing to a new one.
[](http://travis-ci.org/nowsecure/disk-buffer)
## Example
```js
var DiskBuffer = require('disk-buffer');
var b = new DiskBuffer('/tmp/artifacts', {
flushBytes: 1024,
flushWrites: 20
});
b.on('flush', function(flush){
// do something with the file at
// `flush.path`
});
someData().pipe(b);
```
## Installation
```bash
$ npm install disk-buffer
```
## API
### DiskBuffer(path, opts)
Create a new `DiskBuffer`. The `path` given is used for the base of the filenames created, which append ".{pid}.{id}.{fid}".
Options:
- `.flushBytes`: flush after this many bytes written
- `.flushWrites`: flush after this many writes
### `flush` event
For every flush, an event with the following properties is emitted:
- `path`: the file's location
- `opened`: a date object of the file's creation
## Kudos
This is inspired by [tj/go-disk-buffer](https://github.com/tj/go-disk-buffer).
## License
MIT