From 7ad1312830464fa3d5b6c24458fcc89a68dec3d3 Mon Sep 17 00:00:00 2001 From: MuchtarSalimov Date: Tue, 9 Oct 2018 20:17:27 -0400 Subject: [PATCH] Potential rewrite of same change. seeking review @humphd the change you asked for said to rule out undefined, but now that I think about it, isn't the fact that it is undefined the problem? The object has no such attribute, and thats why it breaks. I have written a new way of checking this and would like your opinion on it. I could just undone the == -> === change but I expect that there might be a good reason not to do that. --- src/filesystem/implementation.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index b4c65f4..e11be52 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -1870,12 +1870,17 @@ function appendFile(fs, context, path, data, options, callback) { if(!flags) { return callback(new Errors.EINVAL('flags is not valid', path)); } + + if (typeof options === 'object' && options.encoding === undefined ) { + options.encoding = 'utf8'; + } data = data || ''; if(typeof data === 'number') { data = '' + data; } - if(typeof data === 'string' && (options.encoding === null || options.encoding === 'utf8')) { + + if(typeof data === 'string' && options.encoding === 'utf8') { data = Encoding.encode(data); }