Reputation: 73
I'm creating a text editor using node-webkit. When the user clicks a "Save" menu item, I get write a plain text file to disk using the fs.writeFile() method:
fs.writeFile(file, txt, function (err) {
if (err) throw err;
console.log("file saved");
});
However, it's not saving the entire string passed through the "txt" variable. It's only saving the first 300 characters or so to the file.
I've tried using this method, and the synchronous method fs.writeFileSync. Both are having the same problem. I've tried logging the txt string passed to the method to make sure there's nothing wrong there.
Any ideas why I'm not getting the full text in my saved file?
Upvotes: 3
Views: 2422
Reputation: 11
According to this post: https://groups.google.com/forum/#!topic/node-webkit/3M-0v92o9Zs in the node-webkit Google group, it is likely an encoding issue. Try changing the encoding. I was having the same problem and changed my encoding to utf16le, as specified in that thread, and it fixed the issue; the whole string was written to the file.
My code is now: fs.writeFileSync(path, data, {encoding:'utf16le'});
Upvotes: 1