/*1Copyright (c) 2012, Yahoo! Inc. All rights reserved.2Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.3*/45var util = require('util'),6fs = require('fs'),7Store = require('./index');89/**10* a `Store` implementation that doesn't actually store anything. It assumes that keys11* are absolute file paths, and contents are contents of those files.12* Thus, `set` for this store is no-op, `get` returns the13* contents of the filename that the key represents, `hasKey` returns true if the key14* supplied is a valid file path and `keys` always returns an empty array.15*16* Usage17* -----18*19* var store = require('istanbul').Store.create('fslookup');20*21*22* @class LookupStore23* @extends Store24* @module store25* @constructor26*/27function LookupStore(opts) {28Store.call(this, opts);29}3031LookupStore.TYPE = 'fslookup';32util.inherits(LookupStore, Store);3334Store.mix(LookupStore, {35keys: function () {36return [];37},38get: function (key) {39return fs.readFileSync(key, 'utf8');40},41hasKey: function (key) {42var stats;43try {44stats = fs.statSync(key);45return stats.isFile();46} catch (ex) {47return false;48}49},50set: function (key /*, contents */) {51if (!this.hasKey(key)) {52throw new Error('Attempt to set contents for non-existent file [' + key + '] on a fslookup store');53}54return key;55}56});575859module.exports = LookupStore;60616263