Skip to content

Commit

Permalink
1. add random-access-test as dependency.
Browse files Browse the repository at this point in the history
2. patch empty read issue.
3. patch destroy w/o callback issue.
  • Loading branch information
rhodey committed Jan 15, 2020
1 parent 2ac83cf commit 8751931
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function RASPauseWrapper (ras) {

inherits(RASPauseWrapper, PauseWrapper)

function noop () { }

Object.assign(RASPauseWrapper.prototype, {
open: function (cb) {
var scope = this
Expand All @@ -33,7 +35,11 @@ Object.assign(RASPauseWrapper.prototype, {
})
},
read: function (offset, size, cb) {
this._onResumeCb(cb, function (cbProxy) { this._proxied.read(offset, size, cbProxy) })
if (size === 0) {
this._onResumeCb(cb, function (cbProxy) { cbProxy(null, Buffer.alloc(0)) })
} else {
this._onResumeCb(cb, function (cbProxy) { this._proxied.read(offset, size, cbProxy) })
}
},
write: function (offset, buffer, cb) {
this._onResumeCb(cb, function (cbProxy) { this._proxied.write(offset, buffer, cbProxy) })
Expand All @@ -54,6 +60,7 @@ Object.assign(RASPauseWrapper.prototype, {
})
},
destroy: function (cb) {
cb = cb || noop
this._closed = true
var scope = this
return this._proxied.destroy(function (err) {
Expand Down
17 changes: 17 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
#!/usr/bin/env node
const tape = require('tape')
const randomTest = require('random-access-test')
const ram = require('random-access-memory')
const randomFile = require('random-access-file')
const pauseWrap = require('.')

var opts = {
writable: true,
reopen: true,
del: true,
truncate: false,
size: true,
content: false,
dir: '/tmp/random-pause-test'
}

randomTest(function (filename, opts2, callback) {
var storage = randomFile(opts.dir + '/' + filename, opts2)
callback(pauseWrap(storage))
}, opts)

function pauseRam (buffer) {
return pauseWrap(ram(buffer))
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"random-access-storage": "^1.3.0"
},
"devDependencies": {
"random-access-test": "github:random-access-storage/random-access-test",
"random-access-file": "^2.1.3",
"random-access-memory": "^3.0.0",
"standard": "^12.0.1",
"tape": "^4.9.1"
Expand Down

0 comments on commit 8751931

Please sign in to comment.