Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

1234567891011121314151617181920212223242526272829
  1. var common = require('./common');
  2. var fs = require('fs');
  3. var path = require('path');
  4. //@
  5. //@ ### 'string'.toEnd(file)
  6. //@
  7. //@ Examples:
  8. //@
  9. //@ ```javascript
  10. //@ cat('input.txt').toEnd('output.txt');
  11. //@ ```
  12. //@
  13. //@ Analogous to the redirect-and-append operator `>>` in Unix, but works with JavaScript strings (such as
  14. //@ those returned by `cat`, `grep`, etc).
  15. function _toEnd(options, file) {
  16. if (!file)
  17. common.error('wrong arguments');
  18. if (!fs.existsSync( path.dirname(file) ))
  19. common.error('no such file or directory: ' + path.dirname(file));
  20. try {
  21. fs.appendFileSync(file, this.toString(), 'utf8');
  22. } catch(e) {
  23. common.error('could not append to file (code '+e.code+'): '+file, true);
  24. }
  25. }
  26. module.exports = _toEnd;