-
-
Notifications
You must be signed in to change notification settings - Fork 666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with haxe.io.BytesInput #3148
Comments
Which one, |
The asset is just a standard tar.gz file whose first 3 bytes are in fact 31, 139, 8. |
Ok. But still we need a small example that can reproduce the problem. For example: import haxe.io.*;
import flash.utils.ByteArray;
class Test
{
static function main()
{
var ba = new ByteArray(5);
ba.writeByte(31);
ba.writeByte(139);
ba.writeByte(8);
ba.writeByte(0);
ba.writeByte(0);
var b = Bytes.ofString(ba.toString());
for (i in 0...b.length) {
trace(b.toString().charCodeAt(i));
}
var input = new BytesInput(b);
for (i in 0...b.length) {
trace(input.readByte());
}
}
} compiles with:
It correctly outputs:
Does the above outputs the same for you? |
I'm not sure what you are referring to.. I included the source code above, and the "asset" file in question is ANY standard tar.gz file (they all begin with 31, 139, 8 as the first 3 bytes)... |
Now I tried to create a project that is exactly what you've described, but still it outputted correctly for me without the extra byte you mentioned. Here is my project: https://dl.dropboxusercontent.com/u/2661116/TestHaxe3148.zip |
Ok, I downloaded your zip, compiled it with "lime build flash" and ran it in Flash Player Debugger 11.2.202.228 (12.0) and got the following output (which matches my problem I described above)... Main.hx:17: Byte #0: 31 I have the following libraries installed: actuate: 1.7.3 [1.7.5] Also, I am on a Mac if that matters... |
I see. I thought you were targeting cpp. I can now reproduce it with other targets. import haxe.io.Bytes;
class Test {
static function main():Void {
var b = Bytes.alloc(2);
b.set(0, 31);
b.set(1, 139);
var bstr = b.toString();
trace(bstr.length); //2, correct
var b2 = Bytes.ofString(bstr);
trace(b2.length); //3, but should be 2
for (i in 0...b2.length) {
trace(b2.get(i));
}
}
} Targeting macro, cpp, php (correct):
Targeting flash:
Targeting JS, runs with node:
Targeting java, c#:
Looks like some crossplatform string issue. |
Ah, yes. Sorry for the confusion. Thanks for looking into this. |
Btw, since you're reading a binary file, converting to and from string should be avoided anyway... You could get a #if flash
//for flash, BytesData = flash.utils.ByteArray
var bytes = haxe.io.Bytes.ofData(openfl.Assets.getBytes("assets/Test.tgz"));
#else
//for openfl-native, ByteArray extends Bytes
var bytes = openfl.Assets.getBytes("assets/Test.tgz");
#end |
Yes, I knew that using a string was a bad idea, but I was just testing trying to get it to read the file at all and format was complaining that I wasn't feeding it properly. Before I even submitted this I switched to converting the ByteArray to haxe.io.bytes which seems to work cross-platform, albeit probably not as fast as your method which I'll give a try in a little bit. Thanks for the info! |
This is normal behavior, because the ofString assume UTF8 encoding but here you're inserting an invalid utf8 char into the bytes. In flash/js that would fail when doing bytes.toString but CPP does not check that. We are planning to review this as part of our work on Unicode (see #3072) |
Somewhere in Main.hx
Reader.hx
package;
class Reader
{
var i : haxe.io.Input;
}
MY OUTPUT
Main.hx:48: Byte #0 31
Main.hx:48: Byte #1 139
Main.hx:48: Byte #2 8
Main.hx:48: Byte #3 null
Main.hx:48: Byte #4 null
Reader.hx:19: Byte #0: 31
Reader.hx:19: Byte #1: 194
Reader.hx:19: Byte #2: 139
Reader.hx:19: Byte #3: 8
Reader.hx:19: Byte #4: 0
Where is the 194 byte in Reader.hx Byte #1 coming from?!?!?!? Shouldn't both outputs be the same?
NOTE: All of this stems from trying to read in a tar.gz file from the assets directory and parse it with the Haxe format library so I can let the user skin the application on the fly... Format expects the input to be of type haxe.io.Input, and in order to read assets cross-platform I need to use Assets.getBytes (as far as I understand). Either way, the data appears to be getting corrupted at some point.
The text was updated successfully, but these errors were encountered: