Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fs = require 'fs'
- readline = require('readline');
- exports.countryCounter = (countryCode, cb) ->
- return cb() unless countryCode
- instream = fs.createReadStream("#{__dirname}/../data/geo.txt", {
- flags: 'r',
- encoding: 'utf-8',
- bufferSize: 256 * 1024
- });
- rl = readline.createInterface(instream, null);
- counter = 0
- lines = 0
- rl.on('line', (line) ->
- # process line here
- values = line.split '\t'
- # GEO_FIELD_MIN, GEO_FIELD_MAX, GEO_FIELD_COUNTRY
- # line[0], line[1], line[3]
- if values[3] == countryCode then counter++
- );
- rl.on('close', () ->
- cb null, counter
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement