Closed bcheidemann closed 3 years ago
Let's fix this while you're adding this test.
I think the easiest thing would be to mimic what node does here:
diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index 3027688..67bc8c0 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -1873,8 +1873,8 @@ function writeFile(context, path, data, options, callback) { if(typeof data === 'number') { data = '' + data; } - if(typeof data === 'string' && options.encoding === 'utf8') { - data = Buffer.from(data); + if(typeof data === 'string') { + data = Buffer.from(data, options.encoding || 'utf8'); } open_file(context, path, flags, function(err, fileNode) {
Node does a bit more work to assert the encoding, but I don't know if we care beyond making sure we set the default encoding to
'utf8'
if it's missing.
I've implemented the equivalent of what node is doing, should be good to review now =)
Closes #773
Adds a test which currently fails, demonstrating issue #773