Skip to content

Commit 8751931

Browse files
author
rhodey
committed
1. add random-access-test as dependency.
2. patch empty read issue. 3. patch destroy w/o callback issue.
1 parent 2ac83cf commit 8751931

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function RASPauseWrapper (ras) {
2121

2222
inherits(RASPauseWrapper, PauseWrapper)
2323

24+
function noop () { }
25+
2426
Object.assign(RASPauseWrapper.prototype, {
2527
open: function (cb) {
2628
var scope = this
@@ -33,7 +35,11 @@ Object.assign(RASPauseWrapper.prototype, {
3335
})
3436
},
3537
read: function (offset, size, cb) {
36-
this._onResumeCb(cb, function (cbProxy) { this._proxied.read(offset, size, cbProxy) })
38+
if (size === 0) {
39+
this._onResumeCb(cb, function (cbProxy) { cbProxy(null, Buffer.alloc(0)) })
40+
} else {
41+
this._onResumeCb(cb, function (cbProxy) { this._proxied.read(offset, size, cbProxy) })
42+
}
3743
},
3844
write: function (offset, buffer, cb) {
3945
this._onResumeCb(cb, function (cbProxy) { this._proxied.write(offset, buffer, cbProxy) })
@@ -54,6 +60,7 @@ Object.assign(RASPauseWrapper.prototype, {
5460
})
5561
},
5662
destroy: function (cb) {
63+
cb = cb || noop
5764
this._closed = true
5865
var scope = this
5966
return this._proxied.destroy(function (err) {

index.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
#!/usr/bin/env node
22
const tape = require('tape')
3+
const randomTest = require('random-access-test')
34
const ram = require('random-access-memory')
5+
const randomFile = require('random-access-file')
46
const pauseWrap = require('.')
57

8+
var opts = {
9+
writable: true,
10+
reopen: true,
11+
del: true,
12+
truncate: false,
13+
size: true,
14+
content: false,
15+
dir: '/tmp/random-pause-test'
16+
}
17+
18+
randomTest(function (filename, opts2, callback) {
19+
var storage = randomFile(opts.dir + '/' + filename, opts2)
20+
callback(pauseWrap(storage))
21+
}, opts)
22+
623
function pauseRam (buffer) {
724
return pauseWrap(ram(buffer))
825
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"random-access-storage": "^1.3.0"
1717
},
1818
"devDependencies": {
19+
"random-access-test": "github:random-access-storage/random-access-test",
20+
"random-access-file": "^2.1.3",
1921
"random-access-memory": "^3.0.0",
2022
"standard": "^12.0.1",
2123
"tape": "^4.9.1"

0 commit comments

Comments
 (0)