1 | # Steno [![](http://img.shields.io/npm/dm/steno.svg?style=flat)](https://www.npmjs.org/package/steno) [![Node.js CI](https://github.com/typicode/steno/actions/workflows/node.js.yml/badge.svg)](https://github.com/typicode/steno/actions/workflows/node.js.yml)
|
2 |
|
3 | > Specialized fast async file writer
|
4 |
|
5 | **Steno** makes writing to the same file often/concurrently fast and safe.
|
6 |
|
7 | Used in [lowdb](https://github.com/typicode/lowdb).
|
8 |
|
9 | _https://en.wikipedia.org/wiki/Stenotype_
|
10 |
|
11 | ## Features
|
12 |
|
13 | - Fast (see benchmark)
|
14 | - Lightweight (~6kb)
|
15 | - Promise-based
|
16 | - Atomic write
|
17 | - No race condition
|
18 | - TypeScript definitions
|
19 |
|
20 | ## Usage
|
21 |
|
22 | ```javascript
|
23 | import { Writer } from 'steno'
|
24 |
|
25 | // Create a singleton writer
|
26 | const file = new Writer('file.txt')
|
27 |
|
28 | // Use it in the rest of your code
|
29 | async function save() {
|
30 | await file.write('some data')
|
31 | }
|
32 | ```
|
33 |
|
34 | ## Benchmark
|
35 |
|
36 | `npm run benchmark` (see `src/benchmark.ts`)
|
37 |
|
38 | ```
|
39 | Write 1KB data to the same file x 1000
|
40 |
|
41 | fs : 62.303ms
|
42 | steno : 1.384ms
|
43 |
|
44 | fs.txt = steno.txt ✓
|
45 |
|
46 |
|
47 | Write 1MB data to the same file x 1000
|
48 |
|
49 | fs : 2.300s
|
50 | steno : 5.444ms
|
51 |
|
52 | fs.txt = steno.txt ✓
|
53 | ```
|
54 |
|
55 | ## License
|
56 |
|
57 | MIT - [Typicode](https://github.com/typicode)
|