diff --git a/dist/idbfs.js b/dist/idbfs.js index a30495d..c7701c1 100644 --- a/dist/idbfs.js +++ b/dist/idbfs.js @@ -8866,6 +8866,10 @@ define('src/fs',['require','lodash','encoding-indexes','encoding','src/path','sr callback(new EInvalid('flags is not valid')); } + data = data || ''; + if(typeof data === "number") { + data = '' + data; + } if(typeof data === "string" && options.encoding === 'utf8') { data = new TextEncoder('utf-8').encode(data); } diff --git a/src/fs.js b/src/fs.js index a3ccd31..76ad549 100644 --- a/src/fs.js +++ b/src/fs.js @@ -1317,6 +1317,10 @@ define(function(require) { callback(new EInvalid('flags is not valid')); } + data = data || ''; + if(typeof data === "number") { + data = '' + data; + } if(typeof data === "string" && options.encoding === 'utf8') { data = new TextEncoder('utf-8').encode(data); } diff --git a/tests/spec/node.spec.js b/tests/spec/node.spec.js index c370a0f..fe21914 100644 --- a/tests/spec/node.spec.js +++ b/tests/spec/node.spec.js @@ -108,7 +108,9 @@ describe("node.js tests from https://github.com/joyent/node/blob/master/test", f check(fs.symlink, 'foo\u0000bar', 'foobar'); check(fs.symlink, 'foobar', 'foo\u0000bar'); check(fs.unlink, 'foo\u0000bar'); - check(fs.writeFile, 'foo\u0000bar'); + // NOTE: the node.js test doesn't pass anything for the data arg + // but this just seems wrong based on their docs. Here I use one. + check(fs.writeFile, 'foo\u0000bar', 'foobar'); // TODO - need to be implemented still... // check(fs.appendFile, 'foo\u0000bar'); // check(fs.realpath, 'foo\u0000bar');