From 8751931a87b7b32007d5a7aa49536825259b7a14 Mon Sep 17 00:00:00 2001 From: rhodey Date: Fri, 10 Jan 2020 20:45:00 -0500 Subject: [PATCH] 1. add random-access-test as dependency. 2. patch empty read issue. 3. patch destroy w/o callback issue. --- index.js | 9 ++++++++- index.test.js | 17 +++++++++++++++++ package.json | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8f8c251..5e8728a 100644 --- a/index.js +++ b/index.js @@ -21,6 +21,8 @@ function RASPauseWrapper (ras) { inherits(RASPauseWrapper, PauseWrapper) +function noop () { } + Object.assign(RASPauseWrapper.prototype, { open: function (cb) { var scope = this @@ -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) }) @@ -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) { diff --git a/index.test.js b/index.test.js index d3a9504..70cc9b4 100755 --- a/index.test.js +++ b/index.test.js @@ -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)) } diff --git a/package.json b/package.json index e8fc546..faaeeb0 100644 --- a/package.json +++ b/package.json @@ -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"