wkh237 / react-native-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.61k stars 1.6k forks source link

Android: writeFile with ascii encoding accepts values 0-255 but readFile returns values from -128 to 127 #543

Open sakarit-zz opened 7 years ago

sakarit-zz commented 7 years ago

Version: 0.10.8

So you have this snippet of code:

for(byte b : bytes) {
    asciiResult.pushInt((int)b);
}

But I think what you should be doing is this:

for(byte b : bytes) {
    asciiResult.pushInt((int)b & 0xFF);
}

Reference: https://stackoverflow.com/questions/9581530/converting-from-byte-to-int-in-java

sakarit-zz commented 7 years ago

@wkh237 I created a PR: https://github.com/wkh237/react-native-fetch-blob/pull/544

Couldn't find what is "Bug Fix Branch" 0.10.9 so selected master... please advice.

lll000111 commented 7 years ago

Couldn't find what is "Bug Fix Branch" 0.10.9

Branch "0.10.9" — https://github.com/wkh237/react-native-fetch-blob/tree/0.10.9

sakarit-zz commented 7 years ago

This same thing seems to be happening with iOS also. Is it a feature by design or should it be fixed?

lll000111 commented 7 years ago

Well, is there a problem? I'm not the package owner, I just contributed code and only care about a few limited functions that I myself use, but I ran the quite extensive tests (see https://github.com/lll000111/react-native-fetch-blob-dev/tree/master/test, test-init.js is the starting point, each test file has a few of the total tests) and it works. If you can show a problem....

By the way, you should reference tickets in PRs, just add a "#543" to a commit message (anywhere in addition to the text) and Github will show the commit and/or PR in the issue timeline. While I ran them all when I made changes for my PRs I only looked at the ones relevant for my own functions (such as fs.hash, which I added to RNFB in 0.10.9). So maybe there is an error in the tests, maybe there isn't. Don't know.