| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
var util = require('util'), |
| 7 |
fs = require('fs'), |
| 8 |
Store = require('./index'); |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
function LookupStore(opts) { |
| 29 |
Store.call(this, opts); |
| 30 |
} |
| 31 |
|
| 32 |
LookupStore.TYPE = 'fslookup'; |
| 33 |
util.inherits(LookupStore, Store); |
| 34 |
|
| 35 |
Store.mix(LookupStore, { |
| 36 |
keys: function () { |
| 37 |
return []; |
| 38 |
}, |
| 39 |
get: function (key) { |
| 40 |
return fs.readFileSync(key, 'utf8'); |
| 41 |
}, |
| 42 |
hasKey: function (key) { |
| 43 |
var stats; |
| 44 |
try { |
| 45 |
stats = fs.statSync(key); |
| 46 |
return stats.isFile(); |
| 47 |
} catch (ex) { |
| 48 |
return false; |
| 49 |
} |
| 50 |
}, |
| 51 |
set: function (key ) { |
| 52 |
if (!this.hasKey(key)) { |
| 53 |
throw new Error('Attempt to set contents for non-existent file [' + key + '] on a fslookup store'); |
| 54 |
} |
| 55 |
return key; |
| 56 |
} |
| 57 |
}); |
| 58 |
|
| 59 |
|
| 60 |
module.exports = LookupStore; |
| 61 |
|