Create file with Hexadecimal and ASCII content in nodejs

3

I need to create a flat file with a string that contains hexadecimal and mostly ASCII. The string is something like:

var a = "var x = '\x68\x6F\x6C\x61\x61\x61\x61\x20\x6D\x75\x6E\x64\x69\x6C\x6C\x6F\x6F\x6F\x6F\x6F'";

The contents of the variable a try to write it to a file, but at the moment of creating the file all the hexadecimal content is converted to ASCII. : (

I already tried to modify the string by replacing the \ with double \ but it does not work because the variable was already interpreted and it is not hexadecimal.

This is how I generate the file:

fs.writeFile('paht/file.js', a, 'utf8', function(e, r){
                console.log('litoooo');
            });

I already tried changing the encoding to hex but it does not work either.

At the end of the file output is always:

var x = 'holaaaa mundillooooo'
    
asked by Alfredo Gt 12.10.2016 в 23:00
source

1 answer

0

new Buffer ("here my text", "hex");

Then save it to a file

    
answered by 13.10.2016 в 00:12