Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to remove execPipe function #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 2 additions & 37 deletions lib/wheat/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -268,10 +232,11 @@ var Renderers = module.exports = {
},
function processFile(err, data) {
if (err) { callback(err); return; }
execPipe("dot", ["-Tpng"], data, this);
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"
Expand Down