-
Notifications
You must be signed in to change notification settings - Fork 19
Browser support #5
Comments
browserify uses a compatible Buffer module https://github.com/feross/buffer so that's no problem. However its zlib module (think this is it: https://github.com/brianloveswords/zlib-browserify) lacks
But I haven't tried to run the test suite in the browser yet (not sure how to - does grunt support it?) |
I’m using Grunt + Karma + PhantomJS + Jasmine in another project, that setup has worked well for me there. I’ll see if I can implement that over lunch. |
That setups works well, however I’m having some issues getting the test to use the Browserify-generated bundle. I’ll have another look later. |
Maybe could use https://ci.testling.com for browser tests (free for open source, lots of other browser-related npm modules use it) |
I’ve implemented support directly in the source now (without need for pre or postprocessing with any tool). Citing my comment from the other ticket:
|
Thank you for making a browser only version. I just got this error:
|
Do you have the NBT file for me to reproduce? You can email it to me privately if you don’t want to share online. (Email address is in my profile.) Edit: and perhaps more importantly, the code you used to get the data and invoke parse(). |
This is the NBT-Data: data.bin.txt. EDIT: You can see what I am doing here. |
Seems like the parser doesn't detect compounds correctly. Because the data starts with a compound and the dataType is set to Int8. Also I couldn't force it to use a compound. I tried it with the nbt.parse function and with the compound function of a nbt.Reader object. |
Thanks for your file and testing! Here's what I found:
Addressed in 7a5c23c, along with a related issue (see notes). What wil likely happen now when you try to run your code is that it will throw Hope this helps. If you have any ideas please let me know. |
I updated the library, but I still get the same error as you can see here. |
The library should handle this condition a bit more gracefully, but you’re passing in a string instead of an ArrayBuffer. Per the docs:
I’ve added task #29 to support arrays and strings because that would be useful especially in the browser, despite strings being a bad fit for binary data. In the meantime you can use a conversion routine like this: function stringToArrayBuffer(str) {
if (typeof str !== 'string') throw 'str must be a string';
var i, x, arr = new Uint8Array(str.length);
for (i = 0; i < str.length; i++) {
x = str.charCodeAt(i);
if (x < 0 || x > 255) throw 'Element ' + i + ' out of range: ' + x;
arr[i] = x;
}
return arr.buffer;
} You’re also not checking the |
I thought that the atob-function returns a ByteArray. I'm not dealing with errors, because I couldn't even get a basic setup to work. |
Closing this because the issues you encountered now have separate tasks. If there’s anything else, feel free to open another ticket. |
NBT.js currently does not work in the browser. I think it’s easiest to use a pre-existing Buffer module, if there is one. The test suite should then also be made to run in the browser.
The text was updated successfully, but these errors were encountered: