Fix Files.getBytes on web target #120
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
There is a problem with
Files.getByteson web targets, becausefs.readFileSyncwhen using the encoding option ofbinaryreturns a string.The compiled code:
is attempting to access
data.bufferbut becausedatais a string,bufferis undefined, this caused thenew Uint8Array(data.buffer)to return an empty array in turn causing the bytes returned to simply be empty.The test example
After creating a new ceramic project with
ceramic initin thecreatemethod orpreloadmethod attempt to get bytes from a file on your system.in this case bytes will be

haxe_io_Byteswith a length of 0 with an empty UInt8array and attempting to get the texture from bytes results infailed to load image from bytes, on error: [object Event]Solution
The simplest solution would be to not use the
binaryencoding option fromFiles.getBytesmethod, asreadFileSyncwill set encoding tonulland will return aBufferinstead of a string anddata.bufferwill exist and the array and bytes will no longer be empty.The solution:
I don't believe this will cause any unintended side effects, I have tested the solution in my own projects as well as a test project and there appears to be no further issues.