diff --git a/lib/index.coffee b/lib/index.coffee index ced397c..9f6ccf2 100755 --- a/lib/index.coffee +++ b/lib/index.coffee @@ -108,6 +108,8 @@ class File_DB result = {} for key, position of data func.push @_getdataMaker key, position + unless func.length + return cb null, result flow = ep() flow.lazy func flow.lazy -> @@ -128,6 +130,8 @@ class File_DB result = {} for key, position of data func.push @_popdataMaker key, position + unless func.length + return cb null, result flow = ep() flow.lazy func flow.lazy -> diff --git a/out/release/lib/index.js b/out/release/lib/index.js index 737a1d9..13eaf21 100644 --- a/out/release/lib/index.js +++ b/out/release/lib/index.js @@ -155,6 +155,9 @@ File_DB = (function() { position = data[key]; func.push(_this._getdataMaker(key, position)); } + if (!func.length) { + return cb(null, result); + } flow = ep(); flow.lazy(func); flow.lazy(function() { @@ -196,6 +199,9 @@ File_DB = (function() { position = data[key]; func.push(_this._popdataMaker(key, position)); } + if (!func.length) { + return cb(null, result); + } flow = ep(); flow.lazy(func); flow.lazy(function() { diff --git a/package.json b/package.json index 543db8f..f3cd371 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shared-memory", - "version": "0.1.1", + "version": "0.1.2", "description": "A k-v database using /shm/ to shared memory", "keywords": "shared, memory, kv, db, shm", "homepage": "https://github.com/ericdum/node-shared-memory", diff --git a/test.js b/test.js index 285b831..3cd6439 100644 --- a/test.js +++ b/test.js @@ -145,6 +145,19 @@ describe("getAll", function(){ done() }) }) + + it('get empty data', function(done){ + _c = db.index.getAll; + db.index.getAll = function(cb){ + db.index.getAll = _c; + cb(null, {}) + } + db.getAll(function(err, data){ + expect(err).to.not.be.ok() + expect(data).to.be.eql({}) + done() + }) + }) }); describe("popAll", function(){ @@ -161,6 +174,19 @@ describe("popAll", function(){ }) }) }) + + it('pop empty data', function(done){ + _c = db.index.getAll; + db.index.getAll = function(cb){ + db.index.getAll = _c; + cb(null, {}) + } + db.popAll(function(err, data){ + expect(err).to.not.be.ok() + expect(data).to.be.eql({}) + done() + }) + }) }); function regularExpect(key, value, cb) {