On nodejs express server #1, I receive binary stream data from another nodejs Server #2 in HTTP response. I want encode this data to base64. I have problems with encoding. I did it as shown below.
let result = await axios.post(firmwareDownloadURL, {
id: 'firmware1'
}, {
headers: {
'Content-Type': 'application/json',
}
});
let buff1 = new Buffer.from(result.data);
let base64Firmware1 = buff1.toString('base64');
The value of buff1 is not correct and therefore base64Firmware1 is also wrong. I compared it by reading the firmware file from my system with fs.
let buff2 = fs.readFileSync('./f1.bin');
let base64Firmware2 = buff3.toString('base64');
The buff1 and buff2 do not match.
buff <Buffer ef bf bd ef bf bd ef bf bd 00 01 ef bf bd 48 ef bf bd ef bf bd 01 6d 02 08 22 ef bf bd ef bf bd 0a ef bf bd ef bf bd 6e 6d 02 08 ef bf bd 0a ef bf bd ... 612 more bytes>
buff2 <Buffer a7 a3 fe 00 01 8d 48 a7 a6 01 6d 02 08 22 a7 a3 0a a7 a6 6e 6d 02 08 f1 a7 a3 0a a7 a6 f7 6d 02 08 b4 a7 a3 32 a7 a6 14 6e 02 08 39 a7 a3 06 a7 a6 56 ... 307 more bytes>
Interestingly, when I convert buff2 to string and compare with result.data they match.
if (buff2.toString() === result.data && buff2.toString().length == result.data.length) {
console.log('equal');
}
it prints equal on console. Please help me identify, what am I missing?