Skip to content

Instantly share code, notes, and snippets.

@slayerlab
Last active August 28, 2018 15:11
Show Gist options
  • Save slayerlab/c70e8e1d3fbefd01a4b624c324656f33 to your computer and use it in GitHub Desktop.
Save slayerlab/c70e8e1d3fbefd01a4b624c324656f33 to your computer and use it in GitHub Desktop.
só pra mim não esquecer como funciona essa merda.
var EventEmitter = require('events').EventEmitter,
fs = require('fs'),
util = require('util')
var Event = new EventEmitter(),
readStream = fs.createReadStream(__dirname+'./filename.txt','utf8'),
writeStream = fs.createWriteStream(__dirname+'./filename_new.txt', {flags:'w'}),
tmp_txt = [],
v = {
x: undefined,
y: undefined
}
readStream
.on('close', function () {
var ttxt = tmp_txt
for (var i; 0 < ttxt.length; i++) {
v.x = ttxt[i].z
v.y = ttxt[i].w
}
console.log(util.format('Close %s file', this.path.split('/').pop()))
})
.on('data', function (d_txt) {
tmp_txt += d_txt
Event.emit('close')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment