From 598635b04755554a72463338433ced4b6d255e81 Mon Sep 17 00:00:00 2001 From: Arthur Lee Date: Fri, 17 Apr 2015 00:34:56 -0400 Subject: [PATCH] Pipe http response straight to file --- local-cli/bundle.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/local-cli/bundle.js b/local-cli/bundle.js index ff17b25ffd710a..8eae571d655476 100644 --- a/local-cli/bundle.js +++ b/local-cli/bundle.js @@ -3,24 +3,21 @@ var fs = require('fs'); var OUT_PATH = 'iOS/main.jsbundle'; -function getBundle(flags, callback) { +function getBundle(flags) { var options = { host: 'localhost', port: 8081, path: '/index.ios.bundle?dev=' + flags.dev + '&minify=' + flags.minify }; + var file = fs.createWriteStream(OUT_PATH); + console.log('Requesting bundle from local server'); var req = http.request(options, function(res) { - var bundle = ''; - - res.on('data', function (chunk) { - bundle += chunk; - }); + res.pipe(file); res.on('end', function () { - console.log('Got bundle'); - callback(bundle); + console.log('Successfully saved bundle to ' + OUT_PATH); }); }); @@ -55,14 +52,7 @@ module.exports = { if (flags.help) { showHelp(); } else { - getBundle(flags, function(bundle) { - fs.writeFile(OUT_PATH, bundle, function(err) { - if(err) { - return console.err('Error writing bundle to file', err); - } - console.log('Successfully saved bundle to ' + OUT_PATH); - }); - }); + getBundle(flags); } } }