[SOLVED] What file types default to binary? HTML5 problem

I have trouble loading a binary asset on the HTML5 target. It’s 348kB on cpp as it should be, but HTML5 is loading a 650kB byte array. I think this is because it is of the wrong type, and cpp can load anything as bytes anyway?
.bin, .dat, no extension, an arbitrary extension like .f32, or even .zip all have this problem. It’s weird that these are being loaded as text or something else.

I just realized I could fix this by including the assets like this:

<assets ... exclude="*.bin" />
<assets ... include="*.bin" type="binary" />

But I would just like to know if there’s a file type that defaults to a binary file so I don’t have to do this and can keep using a mixed content asset directory as before.

We use a combination of known extensions:

and if not known, a method to read the file and try and guess whether it is binary or not:

Thanks for the specifications, I didn’t find that in the docs.

It is a HTML5 problem then. Cpp and Neko targets are fine. Reproducable easily this way:

  • openfl create project ba
  • copy e.g. a float32 dump file v_pos.bin into Assets
  • trace(openfl.Assets.getBytes("assets/v_pos.bin").length); in main
//openfl test cpp
Main.hx:14: 346488 //correct
//openfl test html5
Main.hx:14: 615241

I’m seeing this too. It looks like it’s how Haxe Bytes.ofString works on JavaScript compared to C++.

It’s possible that when we load the data as text on HTML5, it inflates the byte size by applying UTF-8 or some other format upon it, or perhaps it’s just the generic nature of the ofString method that’s implemented.

The only solution I see is either a better isText method, or loading all text on HTML5 as bytes, which may hurt performance for a large amount of text files. Open to ideas. In the short-term, I’ll add “bin” as a known binary file extension format

EDIT: Oh, it’s listed as a known extension for binary. I’ll research further :confused:

Okay, this is fixed now in the Lime repository for known types (such as “bin”) :slight_smile:

Can confirm it works with bin. Thanks for the quick fix!

1 Like