Comparing version 0.5.0 to 1.0.0
{ | ||
"name": "steno", | ||
"version": "0.5.0", | ||
"description": "Simple file writer with race condition prevention and atomic writing", | ||
"main": "index.js", | ||
"version": "1.0.0", | ||
"description": "Fast file writer with race condition prevention and atomic writing", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib/index.js", | ||
"lib/index.d.ts" | ||
], | ||
"scripts": { | ||
"test": "node test | tap-dot && standard", | ||
"prepush": "npm test" | ||
"test": "jest", | ||
"build": "del-cli lib && tsc", | ||
"prepare": "husky install", | ||
"prepublishOnly": "npm run build", | ||
"postversion": "git push && git push --tags && npm publish", | ||
"benchmark": "ts-node src/benchmark.ts" | ||
}, | ||
@@ -20,2 +29,3 @@ "repository": { | ||
"asynchronous", | ||
"fast", | ||
"race", | ||
@@ -27,3 +37,3 @@ "condition", | ||
], | ||
"author": "typicode", | ||
"author": "Typicode <typicode@gmail.com>", | ||
"license": "MIT", | ||
@@ -35,11 +45,25 @@ "bugs": { | ||
"devDependencies": { | ||
"after": "^0.8.1", | ||
"husky": "^0.11.1", | ||
"standard": "^6.0.7", | ||
"tap-dot": "^0.2.3", | ||
"tape": "^3.0.1" | ||
"@commitlint/cli": "^12.0.1", | ||
"@commitlint/config-conventional": "^12.0.1", | ||
"@commitlint/prompt-cli": "^12.0.1", | ||
"@tsconfig/node10": "^1.0.7", | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.31", | ||
"@typicode/eslint-config": "^0.1.0", | ||
"del-cli": "^3.0.1", | ||
"husky": "^5.1.3", | ||
"jest": "^26.6.3", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.5.3", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.2.2" | ||
}, | ||
"dependencies": { | ||
"graceful-fs": "^4.1.3" | ||
"eslintConfig": { | ||
"extends": "@typicode", | ||
"parserOptions": { | ||
"project": [ | ||
"./tsconfig.lint.json" | ||
] | ||
} | ||
} | ||
} |
@@ -1,79 +0,50 @@ | ||
# steno [![](http://img.shields.io/npm/dm/steno.svg?style=flat)](https://www.npmjs.org/package/steno) [![](https://travis-ci.org/typicode/steno.svg?branch=master)](https://travis-ci.org/typicode/steno) | ||
# 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) | ||
> Simple file writer with __atomic writing__ and __race condition prevention__. | ||
> Specialized fast async file writer | ||
Can be used as a drop-in replacement to `fs.writeFile()`. | ||
**Steno** makes writing to the same file often/concurrently fast and safe. | ||
Built on [graceful-fs](https://github.com/isaacs/node-graceful-fs) and used in [lowdb](https://github.com/typicode/lowdb). | ||
Used in [lowdb](https://github.com/typicode/lowdb). | ||
## Install | ||
_https://en.wikipedia.org/wiki/Stenotype_ | ||
``` | ||
npm install steno --save | ||
``` | ||
## Features | ||
- Fast | ||
- Lightweight | ||
- Promise-based | ||
- Atomic write | ||
- No race condition | ||
- TypeScript definitions | ||
## Usage | ||
```javascript | ||
const steno = require('steno') | ||
import { Writer } from 'steno' | ||
steno.writeFile('file.json', data, err => { | ||
if (err) throw err | ||
}) | ||
``` | ||
// Create a singleton writer | ||
const file = new Writer('file.txt') | ||
## The problem it solves | ||
### Without steno | ||
Let's say you have a server and want to save data to disk: | ||
```javascript | ||
var data = { counter: 0 } | ||
server.post('/', (req, res) => { | ||
// Increment counter | ||
++data.counter | ||
// Save data asynchronously | ||
fs.writeFile('data.json', JSON.stringify(data), err => { | ||
if (err) throw err | ||
res.end() | ||
}) | ||
}) | ||
// Use it in the rest of your code | ||
async function save() { | ||
await file.write('some data') | ||
} | ||
``` | ||
Now if you have many requests, for example `1000`, there's a risk that you end up with: | ||
## Benchmark | ||
```javascript | ||
// In your server | ||
data.counter === 1000 | ||
`npm run benchmark` | ||
// In data.json | ||
data.counter === 865 // ... or any other value | ||
``` | ||
Write 1KB data to the same file x 1000 | ||
fs : 68.464ms | ||
steno: 0.578ms | ||
Why? Because, `fs.write` doesn't guarantee that the call order will be kept. Also, if the server is killed while `data.json` is being written, the file can get corrupted. | ||
### With steno | ||
```javascript | ||
server.post('/increment', (req, res) => { | ||
++data.counter | ||
steno.writeFile('data.json', JSON.stringify(data), err => { | ||
if (err) throw err | ||
res.end() | ||
}) | ||
}) | ||
Write 1MB data to the same file x 1000 | ||
fs : 2.166s | ||
steno: 1.153ms | ||
``` | ||
With steno you'll always have the same data in your server and file. And in case of a crash, file integrity will be preserved. | ||
if needed, you can also use `steno.writeFileSync()` which offers atomic writing too. | ||
__Important: works only in a single instance of Node.__ | ||
## License | ||
MIT - [Typicode](https://github.com/typicode) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6041
0
72
0
14
51
1
- Removedgraceful-fs@^4.1.3
- Removedgraceful-fs@4.2.11(transitive)