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

random-access-storage

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-access-storage - npm Package Compare versions

Comparing version 2.2.1 to 2.3.0

42

index.js

@@ -22,4 +22,5 @@ const EventEmitter = require('events')

const OPEN_OP = 5
const CLOSE_OP = 6
const DESTROY_OP = 7
const SUSPEND_OP = 6
const CLOSE_OP = 7
const DESTROY_OP = 8

@@ -36,2 +37,3 @@ module.exports = class RandomAccessStorage extends EventEmitter {

this.opened = false
this.suspended = false
this.closed = false

@@ -46,2 +48,3 @@ this.destroyed = false

if (opts.stat) this._stat = opts.stat
if (opts.suspend) this._suspend = opts.suspend
if (opts.close) this._close = opts.close

@@ -106,3 +109,3 @@ if (opts.destroy) this._destroy = opts.destroy

if (!cb) cb = noop
if (this.opened && !this._needsOpen) return queueTick(() => cb(null))
if (this.opened && !this._needsOpen) return nextTickCallback(cb)
queueAndRun(this, new Request(this, OPEN_OP, 0, 0, null, this._needsCreate, cb))

@@ -115,5 +118,16 @@ }

suspend (cb) {
if (!cb) cb = noop
if (this.closed || this.suspended) return nextTickCallback(cb)
this._needsOpen = true
queueAndRun(this, new Request(this, SUSPEND_OP, 0, 0, null, false, cb))
}
_suspend (req) {
this._close(req)
}
close (cb) {
if (!cb) cb = noop
if (this.closed) return queueTick(() => cb(null))
if (this.closed) return nextTickCallback(cb)
queueAndRun(this, new Request(this, CLOSE_OP, 0, 0, null, false, cb))

@@ -172,2 +186,6 @@ }

case OPEN_OP:
if (ra.suspended) {
ra.suspended = false
ra.emit('unsuspend')
}
if (!ra.opened) {

@@ -179,2 +197,9 @@ ra.opened = true

case SUSPEND_OP:
if (!ra.suspended) {
ra.suspended = true
ra.emit('suspend')
}
break
case CLOSE_OP:

@@ -258,2 +283,7 @@ if (!ra.closed) {

case SUSPEND_OP:
if (ra.closed || !ra.opened || ra.suspended) nextTick(this, null)
else ra._suspend(this)
break
case CLOSE_OP:

@@ -308,1 +338,5 @@ if (ra.closed || !ra.opened) nextTick(this, null)

}
function nextTickCallback (cb) {
queueTick(() => cb(null))
}

4

package.json
{
"name": "random-access-storage",
"version": "2.2.1",
"version": "2.3.0",
"description": "Easily make random-access-storage instances",

@@ -11,3 +11,3 @@ "main": "index.js",

"devDependencies": {
"brittle": "^2.3.1",
"brittle": "^3.0.0",
"standard": "^17.0.0"

@@ -14,0 +14,0 @@ },

@@ -71,2 +71,3 @@ # random-access-storage

stat: fn, // sets ._stat
suspend: fn, // sets ._suspend
close: fn, // sets ._close

@@ -101,2 +102,6 @@ destroy: fn // sets ._destroy

#### `storage.suspendable`
True if the storage implements `._suspend`.
#### `storage.closed`

@@ -122,2 +127,10 @@

#### `storage.on('suspend')`
Emitted when the storage is fully suspended
#### `storage.on('unsuspend')`
Emitted when the storage comes out of suspension.
#### `storage.open(cb)`

@@ -218,2 +231,14 @@

#### `storage.suspend([callback])`
Suspend (temporarily close) the storage instance.
#### `storage._suspend(req)`
Implement storage suspend. Defaults to calling `_close`.
Optionally implement this to add a way for your storage instance to temporarily free resources.
Call `req.callback(err)` when the storage has been fully suspended.
#### `storage.close([callback])`

@@ -220,0 +245,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