Created
May 30, 2013 18:39
-
-
Save piscisaureus/5680081 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = require('path'); | |
var files = process.argv.slice(2); | |
console.log(files); | |
nextFile(); | |
function nextFile() { | |
var buffer = ''; | |
var processed = 0, mb = 0; | |
if (!files.length) | |
return onEnd(); | |
var file = files[0]; | |
files.splice(0, 1); | |
var inp = fs.createReadStream(file, 'utf8'); | |
inp.on('data', function(data) { | |
buffer += data; | |
var lines = buffer.split(/\r?\n/); | |
for (var i = 0; i < lines.length - 1; i++) { | |
onLine(lines[i]); | |
} | |
buffer = lines[i]; | |
processed += data.length; | |
var newMb = Math.floor(processed / 1024 / 1024); | |
if (newMb !== mb) { | |
mb = newMb; | |
console.log(mb); | |
} | |
}); | |
inp.on('end', function() { | |
onLine(file, buffer); | |
nextFile(); | |
}); | |
} | |
var seen = {}; | |
function onLine(line) { | |
var m = /-\s*\[(.+?):.*?\]\s*GET\s*(\S+)\s*HTTP.*?"(\d+)"/.exec(line); | |
if (!m) | |
return info('? ' + line); | |
var bucket = m[1]; | |
var dir = m[2]; | |
var status = +m[3]; | |
if (!bucket || !dir) | |
return; | |
if (!/^\/dist\//i.test(dir)) | |
return; | |
if (!/\.(tgz|zip|exe|pkg|msi|tar\.gz)/i.test(dir)) | |
return; | |
// Only count success lines | |
if (status != 200 & status != 206 & status != 304) | |
return; | |
if (!seen[bucket]) | |
seen[bucket] = 1; | |
else | |
seen[bucket]++ | |
info(bucket, dir); | |
} | |
function onEnd() { | |
var exts = []; | |
for (var key in seen) { | |
if (!seen.hasOwnProperty(key)) | |
continue; | |
console.log("%s\t%d", key, seen[key]) | |
} | |
} | |
function info() { | |
//console.log.apply(console, arguments); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment