Socket
Socket
Sign inDemoInstall

fs-write-stream-atomic

Package Overview
Dependencies
11
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.6 to 1.0.7

index.js~

27

index.js

@@ -34,2 +34,4 @@ var fs = require('graceful-fs')

this.__atomicTmp = getTmpname(path)
this.__atomicFinished = false
this.__atomicMoved = false
this.__atomicStream = fs.WriteStream(this.__atomicTmp, options)

@@ -55,2 +57,22 @@ this.__atomicStream.on('error', handleError.bind(this))

function finish () {
if (!this.__atomicFinished) return
if (!this.__atomicMoved) return
PassThrough.prototype.emit.call(this, 'finish')
process.nextTick(function () {
this.emit('close')
}.bind(this))
}
WriteStreamAtomic.prototype.emit = function (event) {
// We'll emit this ourselves, as we need to hold off on emitting it
// until after we've completed putting the final file into place.
// To do otherwise creats a race between finish and close ;_;
if (event === 'finish') {
this.__atomicFinished = true
return finish.call(this)
}
return PassThrough.prototype.emit.apply(this, arguments)
}
WriteStreamAtomic.prototype._flush = function (cb) {

@@ -75,7 +97,6 @@ var writeStream = this

cleanup(err)
process.nextTick(function () {
writeStream.emit('close')
})
writeStream.__atomicMoved = true
finish.call(writeStream)
})
}
}

2

package.json
{
"name": "fs-write-stream-atomic",
"version": "1.0.6",
"version": "1.0.7",
"description": "Like `fs.createWriteStream(...)`, but atomic.",

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

@@ -0,6 +1,13 @@

var fs = require('graceful-fs')
var test = require('tap').test
var path = require('path')
var writeStream = require('../index.js')
var fs = require('fs')
var path = require('path')
var rename = fs.rename
fs.rename = function (from, to, cb) {
setTimeout(function () {
rename(from, to, cb)
}, 100)
}
test('basic', function (t) {

@@ -7,0 +14,0 @@ // open 10 write streams to the same file.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc