Skip to content
Browse files

fix fs.readFileSync() with 2 args

  • Loading branch information...
1 parent 3312535 commit f85fcdbe5f5f6fa9a7d72bdba321e9af5abec291 @feross feross committed with Feb 23, 2014
Showing with 24 additions and 1 deletion.
  1. +1 −1 index.js
  2. +19 −0 test/encoding.js
  3. +4 −0 test/files/encoding.js
View
2 index.js
@@ -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]))()
}
View
19 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') }
+});
View
4 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.
Something went wrong with that request. Please try again.