Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. fs = require 'fs'
  2. readline = require('readline');
  3.  
  4. exports.countryCounter = (countryCode, cb) ->
  5. return cb() unless countryCode
  6.  
  7. instream = fs.createReadStream("#{__dirname}/../data/geo.txt", {
  8. flags: 'r',
  9. encoding: 'utf-8',
  10. bufferSize: 256 * 1024
  11. });
  12.  
  13. rl = readline.createInterface(instream, null);
  14.  
  15. counter = 0
  16. lines = 0
  17.  
  18. rl.on('line', (line) ->
  19. # process line here
  20. values = line.split '\t'
  21. # GEO_FIELD_MIN, GEO_FIELD_MAX, GEO_FIELD_COUNTRY
  22. # line[0], line[1], line[3]
  23. if values[3] == countryCode then counter++
  24. );
  25.  
  26. rl.on('close', () ->
  27. cb null, counter
  28. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement