Skip to content
Browse files

use stream.Readable to get large files from stdin

The previous method was truncating files larger than
65535 bytes when piped in through stdin.

See: http://nodejs.org/api/stream.html#stream_class_stream_readable
  • Loading branch information...
1 parent bc27e5f commit 6a7688b6d21016f7d9f0855fcfbd52ed56d84642 @stepheneb stepheneb committed Sep 8, 2013
Showing with 44 additions and 38 deletions.
  1. +44 −38 Support/jshint-tm.js
View
82 Support/jshint-tm.js
@@ -129,57 +129,63 @@ module.exports = function(options) {
autoupdate(function(err, jshint) {
var file = env.TM_FILEPATH;
var savedFile = fs.readFileSync(file, 'utf8');
- var currentDocument = fs.readFileSync('/dev/stdin').toString();
var title = "JSHint: " + env.TM_FILENAME;
var input = "";
+ var currentDocument = "";
+ var readableStdin = fs.createReadStream('/dev/stdin', { encoding: 'utf8', autoClose: true });
+ readableStdin.on('data', function(chunk) {
+ currentDocument += chunk;
+ });
var body = '';
if (err) {
body += '<div class="error">' + err + '</div>';
}
if (jshint) {
- if (currentDocument.length > 0) {
- input = currentDocument;
- } else {
- input = savedFile;
- }
+ readableStdin.on('end', function() {
+ if (currentDocument.length > 0) {
+ input = currentDocument;
+ } else {
+ input = savedFile;
+ }
- //remove shebang
- input = input.replace(/^\#\!.*/, '');
+ //remove shebang
+ input = input.replace(/^\#\!.*/, '');
- if (!jshint(input, options)) {
- jshint.errors.forEach(function(e, i) {
- if (e) {
- var link = 'txmt://open?url=file://' + escape(file) + '&line=' + e.line + '&column=' + e.character;
- body += ('<a class="txmt" href="' + link + '" id="e' + (i+1) + '">');
- if (i < 9) {
- body += '<b>'+(i+1)+'</b>';
+ if (!jshint(input, options)) {
+ jshint.errors.forEach(function(e, i) {
+ if (e) {
+ var link = 'txmt://open?url=file://' + escape(file) + '&line=' + e.line + '&column=' + e.character;
+ body += ('<a class="txmt" href="' + link + '" id="e' + (i+1) + '">');
+ if (i < 9) {
+ body += '<b>'+(i+1)+'</b>';
+ }
+ body += e.reason;
+ if (e.evidence && !isNaN(e.character)) {
+ body += '<tt>';
+ body += html(e.evidence.substring(0, e.character-1));
+ body += '<em>';
+ body += (e.character <= e.evidence.length) ? html(e.evidence.substring(e.character-1, e.character)) : '&nbsp;';
+ body += '</em>';
+ body += html(e.evidence.substring(e.character));
+ body += '</tt>';
+ }
+ body += '</a>';
}
- body += e.reason;
- if (e.evidence && !isNaN(e.character)) {
- body += '<tt>';
- body += html(e.evidence.substring(0, e.character-1));
- body += '<em>';
- body += (e.character <= e.evidence.length) ? html(e.evidence.substring(e.character-1, e.character)) : '&nbsp;';
- body += '</em>';
- body += html(e.evidence.substring(e.character));
- body += '</tt>';
- }
- body += '</a>';
- }
- });
- }
- }
- if (body.length > 0) {
- fs.readFile(__dirname + '/output.html', 'utf8', function(e, html) {
- html = html.replace('{body}', body);
- html = html.replace('<title>jshint</title>', "<title>" + title + "</title>");
- console.log(html);
- process.exit(205); //show_html
+ });
+ }
+ if (body.length > 0) {
+ fs.readFile(__dirname + '/output.html', 'utf8', function(e, html) {
+ html = html.replace('{body}', body);
+ html = html.replace('<title>jshint</title>', "<title>" + title + "</title>");
+ console.log(html);
+ process.exit(205); //show_html
+ });
+ } else {
+ closeWindowWithTitle(title);
+ }
});
- } else {
- closeWindowWithTitle(title);
}
});
};

0 comments on commit 6a7688b

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