itinance / itinance/react-native-fs

Reading binary file in base64 is changing some symbols

Open
#982 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

I'm reading zipped file from my file system in base64 and after converting to hex I can see the all the Line Feeds ('\n':0x0A) are changed to Carriage Return ('\r':0x0D). Also when it find the two of them "\r\n" it is erasing the Line Feed to be only '\n'.

```
scanFirmwareFile = filePath => {
return new Promise((resolve, reject) => {
var RNFS = require('react-native-fs');

RNFS.readFile(filePath, 'base64')
.then(result => {
let hex = this.convertBase64ToHex(result);
console.log(hex);
let readValueInRawBytes = Buffer.from(result, 'base64');
resolve(readValueInRawBytes);
})
.catch(error => {
reject(error);
console.log(error);
});
});
};

convertBase64ToHex = base64Data => {
const raw = atob(base64Data);
let result = '';
for (let i = 0; i < raw.length; i++) {
const hex = raw.charCodeAt(i).toString(16);
result += hex.length === 2 ? hex : '0' + hex;
}
return result.toUpperCase();
};

```
Screen Shot 2021-02-18 at 12 28 10 PM

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.