Skip to content

Commit

Permalink
fix fs.readFileSync() with 2 args
Browse files Browse the repository at this point in the history
  • Loading branch information
feross authored and James Halliday committed Feb 24, 2014
1 parent 3312535 commit f85fcdb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -77,7 +77,7 @@ module.exports = function (file) {
var fpath = Function(vars, t)(file, dirname);

var enc = 'utf8';
if (!/^Function/.test(args[1]) && args[2]) {
if (args[1] && !/^Function/.test(args[1].type)) {
enc = Function('return ' + unparse(args[1]))()
}

Expand Down
19 changes: 19 additions & 0 deletions test/encoding.js
@@ -0,0 +1,19 @@
var test = require('tap').test;
var browserify = require('browserify');

var vm = require('vm');
var path = require('path');

test('sync string encoding', function (t) {
t.plan(1);
var b = browserify(__dirname + '/files/encoding.js');
b.transform(path.dirname(__dirname));
b.bundle(function (err, src) {
if (err) t.fail(err);
vm.runInNewContext(src, {
setTimeout: setTimeout,
console: { log: log }
});
});
function log (msg) { t.equal(msg, '3c623e6265657020626f6f703c2f623e0a') }
});
4 changes: 4 additions & 0 deletions test/files/encoding.js
@@ -0,0 +1,4 @@
var fs = require('fs');
var txt = fs.readFileSync(__dirname + '/robot.html', { encoding: 'hex' });

console.log(txt);

0 comments on commit f85fcdb

Please sign in to comment.