Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

steno

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

steno - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

7

index.js

@@ -18,2 +18,3 @@ var fs = require('fs')

this._callback = cb
return this
}

@@ -54,7 +55,9 @@

}
return this
}
module.exports = function(filename) {
var _filename = path.resolve(filename)
return writers[_filename] = writers[_filename] || new Writer(filename)
filename = path.resolve(filename)
return writers[filename] = writers[filename] || new Writer(filename)
}
{
"name": "steno",
"version": "0.3.1",
"version": "0.3.2",
"description": "Fast non-blocking file writer for Node",

@@ -5,0 +5,0 @@ "main": "index.js",

# steno [![](https://badge.fury.io/js/steno.svg)](http://badge.fury.io/js/steno) [![](https://travis-ci.org/typicode/steno.svg?branch=master)](https://travis-ci.org/typicode/steno)
> Super fast and safe non-blocking file writer for Node
> Fast and safe file writer that prevents race condition

@@ -18,3 +18,3 @@ ```javascript

// Very slow but file's content will always be 10000
for (var i = 0; i < 10000; i++) {
for (var i = 0; i <= 10000; i++) {
fs.writeFileSync('file.txt', i)

@@ -26,3 +26,3 @@ }

// Very fast but file's content may be 5896, 2563, 9856, ...
for (var i = 0; i < 10000; i++) {
for (var i = 0; i <= 10000; i++) {
fs.writeFile('file.txt', i, function() {})

@@ -36,3 +36,3 @@ }

// Very fast and file's content will always be 10000
for (var i = 0; i < 10000; i++) {
for (var i = 0; i <= 10000; i++) {
steno('file.txt').write(i)

@@ -55,3 +55,3 @@ }

When file is being written, data is stored in memory and flushed to disk as soon as possible. Please note also that steno skips intermediate data (B in this example).
When file is being written, data is stored in memory and flushed to disk as soon as possible. Please note also that steno skips intermediate data (B in this example) and assumes to be run in a single process.

@@ -66,13 +66,37 @@ ## Methods

Writes data to file. If file is already being written, data is buffered until it can be written. An optional callback can also be set to be notified when data has been written to disk.
Writes data to file. If file is already being written, data is buffered until it can be written.
```javascript
steno('file.txt').write('data')
```
An optional callback can be set to be notified when data has been flushed.
```javascript
function w(data) {
steno('file.txt').write(data, function(err) {
if (err) throw err
console.log('OK')
})
}
w('A')
w('B')
w('C')
// OK
// OK
// OK
```
__writer.setCallback(cb)__
Sets a writer level callback that is called only after file has been written. Useful for creating atomic writers, logging, delaying, ...
Sets a writer level callback that is called __only__ after file has been written. Useful for creating atomic writers, logging, delaying, ...
```javascript
var atomicWriter = steno('tmp-file.txt').setCallback(function(err, data, next) {
var atomicWriter = steno('tmp.txt').setCallback(function(err, data, next) {
if (err) throw err
fs.rename('tmp-file.txt', 'file.txt', function(err) {
fs.rename('tmp.txt', 'file.txt', function(err) {
if (err) throw err
console.log('OK')
next()

@@ -82,3 +106,10 @@ })

atomicWriter.write('Hello world')
atomicWriter.write('A')
atomicWriter.write('B')
atomicWriter.write('C')
// OK
// OK
// File has been actually written twice
```

@@ -85,0 +116,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc