using streaming ahr

This commit is contained in:
AJ ONeal 2010-11-29 00:44:27 -07:00
bovenliggende 566186f8ba
commit 8eebc915a2
1 gewijzigde bestanden met toevoegingen van 16 en 17 verwijderingen

Bestand weergeven

@ -2,13 +2,11 @@
"use strict"; "use strict";
(function (undefined) { (function (undefined) {
var fs = require('fs'), var fs = require('fs'),
url = require('url'), request = require('ahr'),
ahr = require('ahr'),
stream, stream,
node = process.argv[0], node = process.argv[0],
self = process.argv[1], self = process.argv[1],
fulluri = process.argv[2], fulluri = process.argv[2];
uri;
self = self.substr(self.lastIndexOf('/') + 1); self = self.substr(self.lastIndexOf('/') + 1);
@ -167,7 +165,12 @@
*/ */
} }
function parseData(err, x, data) { var data = '';
function parseData(err, x, chunk, end) {
if (!end) {
data += chunk.toString();
return;
}
var lines = data.split('\n'), var lines = data.split('\n'),
heads = [], heads = [],
curHead; curHead;
@ -189,18 +192,14 @@
return; return;
} }
uri = url.parse(fulluri, true); request.get(fulluri, undefined, { stream: true}).when(parseData);
if (!uri.protocol) {
uri.protocol = ''; //if ('file' !== uri.protocol && '' === uri.protocol || uri.protocol.match(/^http[s]?:$/)) {
} // request.get(fulluri, undefined, { stream: true}).when(parseData);
if ('file:' === uri.protocol || '' === uri.protocol) { //} else {
readFile(uri.pathname).when(parseData); // usage();
} else if (uri.protocol.match(/^http[s]?:$/)) { // return;
ahr.get(fulluri).when(parseData); //}
} else {
usage();
return;
}
} }
main(); main();