Skip to content

Commit

Permalink
Merge pull request #245 from alibaba/fix-write-file-buffer-content
Browse files Browse the repository at this point in the history
fix: should transfer type to string or buffer when writefile
  • Loading branch information
jeasonstudio committed Mar 16, 2021
2 parents 4e48941 + b1e419c commit 6615d53
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/common/writefile.js
Expand Up @@ -4,12 +4,16 @@
*/

const fs = require('fs');
const Buffer = require('buffer').Buffer;

module.exports = async function (filename, content) {
module.exports = async function(filename, content) {
return new Promise((resolve, reject) => {
fs.writeFile(filename, String(content), err => {
if (typeof content !== 'string' && !Buffer.isBuffer(content)) {
content = String(content);
}
fs.writeFile(filename, content, (err) => {
if (err) return reject(err);
resolve(filename);
});
});
};
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "dawn",
"version": "1.9.1",
"version": "1.9.3",
"description": "dawn cli",
"main": "./lib/index.js",
"bin": {
Expand Down

0 comments on commit 6615d53

Please sign in to comment.