Search code examples
embedhaxeopenfl

Better way to bypass Haxe 16MB embedding file size limit?


I just noticed that Haxe (openFL) limits a single embed file's size to 16MB when using the @:file tag(or openfl.Assets). Flash/Flex can embed much larger files directly. My way to solve the problem is to split one large file to several smaller files and combine them at run time. But this is not so convenient sometimes. So is there any better way to bypass this limit in Haxe?


Solution

  • First of all, embedding files of this big size is generally not a good idea:

    • binary size is huge
    • is slows down compilation(because you need to copypaste quite a big amount of data every time
    • this data is forced to be stored in RAM/swap while application is running

    But, speaking of solving the exact problem... I'm not exactly sure if swf allows to embed this big chunks of data at all(need to look at bytecode specs), but in any case it seems that the limitation is there because of ocaml inner limitation on string size. It can be fixed, I believe, however you need to rewrite part of haxe swf generator.

    If you don't want to fix compiler(which may not be possible in case swf doesn't allow to embed this big chunks), then you may just go with a simple macro, which will transparently slice your file in parts, embed and reassemble in runtime.