Skip to content
Browse files

Use stdin instead of opening a file first

  • Loading branch information...
1 parent a4fd565 commit a75c5767c8b97d7ace76c1b53c98cf12a101c0ff @davglass davglass committed Aug 24, 2012
Showing with 19 additions and 14 deletions.
  1. +19 −14 nodejs-coverage/lib/index.js
View
33 nodejs-coverage/lib/index.js
@@ -23,40 +23,48 @@ var cover = function(item, options, callback) {
options = { charset: 'utf8' };
}
- getFile(item, options.name, function(err, file, rm) {
- coverFile(file, options, callback, rm);
+ getString(item, function(err, file) {
+ coverString(file, options, callback);
});
};
-var getFile = function(str, name, callback) {
+var getString = function(str, callback) {
exists(str, function(y) {
if (y) {
- callback(null, str);
- } else {
- //Write Temp File..
- var tmpFile = name || path.join(__dirname, 'tmp-' + (new Date()).getTime() + '.' + (++idx));
- fs.writeFile(tmpFile, str, 'utf8', function(err) {
- callback(null, tmpFile, true);
+ fs.readFile(str, 'utf8', function(err, data) {
+ //Set the type from the file name
+ callback(err, data);
});
+ } else {
+ callback(null, str);
}
});
};
-var coverFile = function(file, options, callback, rm) {
+var coverString = function(str, options, callback) {
var args = [
'-jar',
jar,
'--charset',
options.charset,
- file
+ '--stdin'
], buffer = '', errBuffer = '', child;
+
+
+ if (options.name) {
+ args.push('--cover-name');
+ args.push(options.name);
+ }
child = spawn('java', args, {
stdio: ['pipe', 'pipe', 'pipe']
});
+ child.stdin.write(str);
+ child.stdin.end();
+
child.stdout.on('data', function(chunk) {
buffer += chunk;
});
@@ -69,9 +77,6 @@ var coverFile = function(file, options, callback, rm) {
if (errBuffer) {
err = errBuffer;
}
- if (rm) {
- fs.unlink(file);
- }
callback(err, buffer, errBuffer);
});
};

0 comments on commit a75c576

Please sign in to comment.
Something went wrong with that request. Please try again.