Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix fs.readFileSync() with 2 args #17

Closed
wants to merge 1 commit into from

1 participant

Feross Aboukhadijeh
Feross Aboukhadijeh

Right now this doesn't work:

var txt = fs.readFileSync(__dirname + '/robot.html', { encoding: 'hex' });

With this PR, it now works. Test added, too.

I think your logic on the function test had two bugs and they canceled each other out. (found with the help of @dcposch)

Feross Aboukhadijeh

merged in 0.2.2 so closing

Feross Aboukhadijeh feross closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 24, 2014
  1. Feross Aboukhadijeh
This page is out of date. Refresh to see the latest.
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
2  index.js
View
@@ -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]))()
}
19 test/encoding.js
View
@@ -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 test/files/encoding.js
View
@@ -0,0 +1,4 @@
+var fs = require('fs');
+var txt = fs.readFileSync(__dirname + '/robot.html', { encoding: 'hex' });
+
+console.log(txt);
Something went wrong with that request. Please try again.