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

atomic-file

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atomic-file - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

2

fs.js

@@ -1,2 +0,2 @@

var fs = require('fs')
module.exports = function (file) {

@@ -3,0 +3,0 @@ return {

'use strict'
var fs = require('fs')
var mutexify = require('mutexify')
function isFunction (f) {
return 'function' === typeof f
}
function onceAtATime (fn, queue) {
queue = queue || []
return function () {
var args = [].slice.call(arguments)
if(queue.length)
return queue.push(function () {
fn.apply(null, args)
})
//should be a the callback...
var cb = args.pop()
if(!isFunction(cb)) throw new Error('cb must be provided')
queue.push(cb)
args.push(function done (err) {
var _queue = queue
queue = []
while(_queue.length) _queue.shift()(err)
})
fn.apply(null, args)
}
}
module.exports = function (store, _codec) {
var codec = _codec || require('flumecodec/json')
var queue = []
var lock = mutexify()
var value

@@ -50,15 +23,20 @@

//only allow one update at a time.
set: onceAtATime(function put (_value, cb) {
store.set(codec.encode(_value), function (err) {
if(err) return cb(err)
else cb(null, value=_value)
set: function (_value, cb) {
lock(function (unlock) {
store.set(codec.encode(_value), function (err) {
if(!err) value=_value
unlock(cb, err, _value)
})
})
}, queue),
destroy: onceAtATime(function destroy (cb) {
store.destroy(function (err) {
cb(err, value=null)
},
destroy: function (cb) {
lock(function (unlock) {
store.destroy(function (err) {
value=null
unlock(cb, err)
})
})
}, queue)
}
}
}
{
"name": "atomic-file",
"description": "",
"version": "2.0.1",
"version": "2.1.0",
"homepage": "https://github.com/dominictarr/atomic-file",

@@ -12,3 +12,4 @@ "repository": {

"flumecodec": "0.0.1",
"idb-kv-store": "^4.4.0"
"idb-kv-store": "^4.5.0",
"mutexify": "^1.2.0"
},

@@ -19,3 +20,3 @@ "devDependencies": {

"scripts": {
"test": "set -e; for t in test/*.js; do node $t; done"
"test": "tape 'test/**/*.js'"
},

@@ -22,0 +23,0 @@ "browser": {

@@ -7,4 +7,3 @@ const IdbKvStore = require('idb-kv-store')

const storename = parts.join('/')
const store = new IdbKvStore(storename)
var value
const store = new IdbKvStore(storename, { disableBroadcast: true })
return {

@@ -11,0 +10,0 @@ set: function (value, cb) {

Sorry, the diff of this file is not supported yet

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