node.js - counter not running inside coffeescript createInterface function -
i want make function "countryipcounterstream" read large text file lines in format: 100575232 100577279 5.254.168.0 - 5.254.175.255 se - , calculate sum of absolute difference between numbers in 1st , 2nd column 4th column code == countrycode given function argument.
problem in line: if line[3] == countrycode counter= +line[1]-+line[0]
clause counter= +line[1]-+line[0]
after "then" won't work! however, noticed if replace else, replaced part after "then" runs perfectly. example console.log line[x].
code followed:
exports.countryipcounterstream = (countrycode, cb) -> return cb() unless countrycode heapusagebefore = process.memoryusage().heapused console.log "program init normally, " instream = fs.createreadstream "#{__dirname}/../data/geo.txt", 'utf8' console.log "streaming started" line_counter = 0 outstream = new stream instream.on('data', (chunk) -> console.log chunk.length in [0...chunk.length-1] 1 if chunk[i] == 10 line_counter += 1 ) console.log 'line_counter', line_counter rl = readline.createinterface(instream, outstream) console.log 'country:', countrycode counter = 0 rl.on('line', (line) -> line = line.split '\t' counter += 1 if line[3] == countrycode counter= +line[1]-+line[0] ) rl.close() console.log "finishing up, counter = ", counter heapusageafter = process.memoryusage().heapused heapusageincrease = heapusageafter / heapusagebefore console.log heapusageincrease.tofixed(2) cb null, counter
Comments
Post a Comment