const unzipper = require('./unzip');
const request = require('request');
const Stream = require('stream');
const fs = require('fs');

//request('http://geolite.maxmind.com/download/geoip/database/GeoLite2-City-CSV.zip')
fs.createReadStream('/home/zjonsson/Downloads/GeoLite2-City-CSV_20170207.zip')
  .pipe(unzipper.Parse({}))
  .pipe(Stream.Transform({
    transform: (entry,e,cb) =>  {
      console.log(entry)
      let path = /\/(.*)$/.exec(entry.path)[1];
      console.log(path);
  entry.on('error', e => console.log(e))
  
  .on('finish', () => console.log('done'));
    
entry.pipe(fs.createWriteStream(path))
        .on('finish',() => cb());
    },
    objectMode: true
  }))
  
  setTimeout(()=>null,1000)