fix: handle case data = 0 in writeFile

This commit is contained in:
Ben Heidemann 2021-04-18 16:18:45 +01:00 committed by David Humphrey
parent f9c5473c49
commit 90db749ee5
1 changed files with 1 additions and 2 deletions

View File

@ -1869,7 +1869,6 @@ function writeFile(context, path, data, options, callback) {
return callback(new Errors.EINVAL('flags is not valid', path));
}
data = data || '';
if(!Buffer.isBuffer(data)) {
if(typeof data === 'number') {
data = '' + data;
@ -1878,7 +1877,7 @@ function writeFile(context, path, data, options, callback) {
data = Buffer.from(data.toString());
}
else {
data = Buffer.from(data, options.encoding || 'utf8');
data = Buffer.from(data || '', options.encoding || 'utf8');
}
}