V
V
Valery V.2019-02-15 14:32:17
Node.js
Valery V., 2019-02-15 14:32:17

How to save a binary string to a file?

Good afternoon!
I get a binary file, convert it to a string:

let result = await rp(params);  // request-promise 
    if (result) {
      let file= new Buffer(result).toString('base64');
    }

Can't save this file back:
let file= new Buffer(stringBase64, 'base64').toString();
      fs.writeFile(fileName, file, 'binary', (error) => {
        if (error) {
          throw error;
        }
      });

For some reason it doesn't work properly. How to save from string to file correctly?
Thank you!
PS pipe is not required.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery V., 2019-02-15
@OlegOleg1980

Found it myself:
You need to insert the binary format.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question