write.js 507 B

12345678910111213141516171819
  1. 'use strict';
  2. var assert = require('assert');
  3. module.exports = function (filepath, contents, stat) {
  4. assert(
  5. typeof contents === 'string' || contents instanceof Buffer,
  6. 'Expected `contents` to be a String or a Buffer'
  7. );
  8. var file = this.store.get(filepath);
  9. file.isNew = file.contents === null;
  10. file.state = 'modified';
  11. file.contents = typeof contents === 'string' ? Buffer.from(contents) : contents;
  12. file.stat = stat;
  13. this.store.add(file);
  14. return file.contents.toString();
  15. };