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

123456789101112131415161718192021222324252627282930
  1. var through = require('through');
  2. var fs = require('fs');
  3. module.exports = function () {
  4. var line = '';
  5. var stream = through(write, flush);
  6. return stream;
  7. function write(buf) {
  8. for (var i = 0; i < buf.length; i++) {
  9. var c = typeof buf === 'string'
  10. ? buf.charAt(i)
  11. : String.fromCharCode(buf[i])
  12. ;
  13. if (c === '\n') flush();
  14. else line += c;
  15. }
  16. }
  17. function flush() {
  18. if (fs.writeSync && /^win/.test(process.platform)) {
  19. try { fs.writeSync(1, line + '\n'); }
  20. catch (e) { stream.emit('error', e); }
  21. } else {
  22. try { console.log(line); }
  23. catch (e) { stream.emit('error', e); }
  24. }
  25. line = '';
  26. }
  27. };