write-buffer.js 658 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. var fo = require('../../file-operations');
  3. function writeBuffer(file, optResolver, onWritten) {
  4. var flags = fo.getFlags({
  5. overwrite: optResolver.resolve('overwrite', file),
  6. append: optResolver.resolve('append', file),
  7. });
  8. var opt = {
  9. mode: file.stat.mode,
  10. flags: flags,
  11. };
  12. fo.writeFile(file.path, file.contents, opt, onWriteFile);
  13. function onWriteFile(writeErr, fd) {
  14. if (writeErr) {
  15. return fo.closeFd(writeErr, fd, onWritten);
  16. }
  17. fo.updateMetadata(fd, file, onUpdate);
  18. function onUpdate(updateErr) {
  19. fo.closeFd(updateErr, fd, onWritten);
  20. }
  21. }
  22. }
  23. module.exports = writeBuffer;