fix: allow encodings other that utf8 when using writeFile

This commit is contained in:
Ben Heidemann 2021-04-18 16:15:02 +01:00 committed by David Humphrey
parent 7b1c3e85ce
commit f5ad682fd7
1 changed files with 10 additions and 5 deletions

View File

@ -1870,11 +1870,16 @@ function writeFile(context, path, data, options, callback) {
} }
data = data || ''; data = data || '';
if(!Buffer.isBuffer(data)) {
if(typeof data === 'number') { if(typeof data === 'number') {
data = '' + data; data = '' + data;
} }
if(typeof data === 'string' && (options.encoding || 'utf8') === 'utf8') { if(typeof data !== 'string') {
data = Buffer.from(data); data = Buffer.from(data.toString());
}
else {
data = Buffer.from(data, options.encoding || 'utf8');
}
} }
open_file(context, path, flags, function(err, fileNode) { open_file(context, path, flags, function(err, fileNode) {