diff --git a/lib/data/data.coffee b/lib/data/data.coffee index ad3b7ef0..2ff452ae 100644 --- a/lib/data/data.coffee +++ b/lib/data/data.coffee @@ -20,8 +20,12 @@ constructPath = (key) -> return result exports.get = haltIfNoPrefix (key, options, callback) -> - keyPath = constructPath(key) - fs.readFile(keyPath, options, callback) + exports.has key, (hasKey) -> + if not hasKey + return callback?(null) + + keyPath = constructPath(key) + fs.readFile(keyPath, options, callback) exports.set = haltIfNoPrefix (key, value, options, callback) -> keyPath = constructPath(key) diff --git a/lib/data/data.spec.coffee b/lib/data/data.spec.coffee index 593f6789..8cf14f8d 100644 --- a/lib/data/data.spec.coffee +++ b/lib/data/data.spec.coffee @@ -97,6 +97,12 @@ describe 'Data:', -> expect(value).to.not.exist done() + it 'should return undefined if key doesn\'t exists', (done) -> + data.get 'nontexistantkey', encoding: 'utf8', (error, value) -> + expect(error).to.not.exist + expect(value).to.be.undefined + done() + describe '#has()', -> it 'should return true if a file exists', (done) ->