Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should not throw when getting non-existant keys #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 16 additions & 6 deletions endpoints.js
Expand Up @@ -15,9 +15,9 @@ module.exports = function (basedir, exports) {

/*
okay, so this is gonna run in the browser, attached to localStorage also.


*/

*/
exports.put = function (key, opts) {
var _key = hash(key)
var dir = _key.substring(0, 2)
Expand All @@ -40,19 +40,29 @@ module.exports = function (basedir, exports) {
exports.get = function (key, opts) {
var _key = hash(key)
var dir = _key.substring(0, 2)
return fs.createReadStream(join(basedir, dir, key), opts)
var stream = es.gate(true)
exports.has(key, function (err, stat) {
if (err)
return stream.end()

stream.open()

fs.createReadStream(join(basedir, dir, key), opts)
.pipe(stream)
})
return stream
}

exports.has = function (key, callback) {
var _key = hash(key)
var dir = _key.substring(0, 2)
fs.stat(join(basedir, dir, key), callback)
fs.stat(join(basedir, dir, key), callback)
}

function del(key, cb) {
var _key = hash(key)
var dir = _key.substring(0, 2)
var file = _key.substring(2)
var file = _key.substring(2)
}

return exports
Expand Down
3 changes: 3 additions & 0 deletions test/index.js
Expand Up @@ -20,5 +20,8 @@ rm('/tmp/kv_test', function () {
assert.equal(data.hello, r)
})
})

// should not throw for getting keys that does not exist
kv.get("bar")
})