read.js 395 B

12345678910111213141516
  1. 'use strict';
  2. module.exports = function (filepath, options) {
  3. options = options || {raw: false};
  4. var file = this.store.get(filepath);
  5. if (file.state === 'deleted' || file.contents === null) {
  6. if ('defaults' in options) {
  7. return options.defaults;
  8. }
  9. throw new Error(filepath + ' doesn\'t exist');
  10. }
  11. return options.raw ? file.contents : file.contents.toString();
  12. };