itinance / itinance/react-native-fs
Reading binary file in base64 is changing some symbols
- 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();
};
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.