docsforadobe / aequery

MIT License
41 stars 8 forks source link

Add encoding flag to lib/misc/file.js #22

Closed runegan closed 7 years ago

runegan commented 7 years ago

Original report by Zack Lovatt (Bitbucket: zlovatt, GitHub: zlovatt).


Proposal below; thoughts? Would apply to readFile as well, I think.

#!javascript

    writeFile: function(filePath, contents, encoding) {
        var file = aeq.getFileObject(filePath);
        if (!file.exists) {
            var folder = new Folder( file.path );
            if ( !folder.exists ) {
                folder.create();
            }
        }
        if (!aeq.isNullOrUndefined(encoding))
            file.encoding = encoding;
        file.open("w");
        var success = file.write(contents);
        file.close();
        return success;
    }
runegan commented 7 years ago

Original comment by Rune Gangsø (Bitbucket: runegan, GitHub: runegan).


That's a good idea. You could maybe go further by specify a default encoding? Mac uses UTF-8 and Windows uses some other incompatible format. It would be nice if they both used UTF-8 so you don't get any errors when writing files. Can't remember now but I have had some trouble with the before and the solution was to set UTF-8 explicitly.

runegan commented 7 years ago

Original comment by Zack Lovatt (Bitbucket: zlovatt, GitHub: zlovatt).


misc/file.js: Adds encoding argument, defaults to UTF-8 (resolve #22)