From a820a089532186fac521755c1caf581397dfdc3a Mon Sep 17 00:00:00 2001 From: CrypticSwarm Date: Wed, 9 May 2012 15:53:44 -0500 Subject: [PATCH 1/2] attempt to remove execPipe function --- lib/wheat/renderers.js | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/lib/wheat/renderers.js b/lib/wheat/renderers.js index 8539e10..5cf3d48 100644 --- a/lib/wheat/renderers.js +++ b/lib/wheat/renderers.js @@ -8,42 +8,6 @@ var Git = require('git-fs'), getMime = require('simple-mime')('application/octet-string'), Step = require('step'); -// Execute a child process, feed it a buffer and get a new buffer filtered. -function execPipe(command, args, data, callback) { - var child = ChildProcess.spawn(command, args); - var stdout = [], stderr = [], size = 0; - child.stdout.on('data', function onStdout(buffer) { - size += buffer.length; - stdout[stdout.length] = buffer; - }); - child.stderr.on('data', function onStderr(buffer) { - stderr[stderr.length] = buffer; - }); - child.on('error', function onExit(err) { - callback(err); - }); - child.on('exit', function onExit(code) { - if (code > 0) { - callback(new Error(stderr.join(""))); - } else { - var buffer = new Buffer(size); - var start = 0; - for (var i = 0, l = stdout.length; i < l; i++) { - var chunk = stdout[i]; - chunk.copy(buffer, start); - start += chunk.length; - } - callback(null, buffer); - } - }); - if (typeof data === 'string') { - child.stdin.write(data, "binary"); - } else { - child.stdin.write(data); - } - child.stdin.end(); -} - // This writes proper headers for caching and conditional gets // Also gzips content if it's text based and stable. function postProcess(headers, buffer, version, path, callback) { @@ -268,7 +232,7 @@ var Renderers = module.exports = { }, function processFile(err, data) { if (err) { callback(err); return; } - execPipe("dot", ["-Tpng"], data, this); + ChildProcess.exec("dot -Tpng", this).stdin.end(data, 'binary'); }, function finish(err, buffer) { if (err) { callback(err); return; } From 7a3bccb4c0ffe6442f96e2f67288c93b915f5667 Mon Sep 17 00:00:00 2001 From: CrypticSwarm Date: Fri, 7 Sep 2012 06:53:09 -0500 Subject: [PATCH 2/2] dot files now render correctly Had a problem with encoding. Exec contrary to the docs is handing back a string not a buffer. --- lib/wheat/renderers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/wheat/renderers.js b/lib/wheat/renderers.js index 5cf3d48..99438ae 100644 --- a/lib/wheat/renderers.js +++ b/lib/wheat/renderers.js @@ -232,10 +232,11 @@ var Renderers = module.exports = { }, function processFile(err, data) { if (err) { callback(err); return; } - ChildProcess.exec("dot -Tpng", this).stdin.end(data, 'binary'); + ChildProcess.exec('dot -Tpng', { encoding: 'binary' }, this).stdin.end(data) }, function finish(err, buffer) { if (err) { callback(err); return; } + buffer = new Buffer(buffer, 'binary') postProcess({ "Content-Type": "image/png", "Cache-Control": "public, max-age=32000000"