buffer-browserify
buffer-browserify copied to clipboard
node.js simple tests
I tried to run this module with the Buffer tests from node ( https://github.com/joyent/node/blob/master/test/simple/test-buffer.js )
Tests run in Chrome 19.0.1084.52 m. May not all tests can be fixed...
I tried to omit duplicate errors.
This are the results:
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L33
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L48
TypeError: Object #<error> has no method 'copy'
at Buffer.copy (buffer-browserify/index.js:598:22)
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L186
AssertionError: "hello world" == "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
writing and reading via buffer[number]
does not work. This causes that error. (and that in L207)
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L250
Error: Unknown encoding
at Function.byteLength (buffer-browserify/index.js:58:13)
at new Buffer (buffer-browserify/index.js:323:30)
Encodings: 'ucs2', 'utf-16le', 'binary'
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L320
the base64 decoder should ignores whitespace and illegal chars.
Invalid string. Length must be a multiple of 4
https://github.com/beatgammit/base64-js/blob/master/lib/b64.js#L10 should throw an Error not a string!
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L343
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L379 and more
Invalid string. Length must be a multiple of 4
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L432
TypeError: Object #<error> has no method 'binarySlice'
at Buffer.toString (buffer-browserify/index.js:512:26)
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L569
TypeError: Object #<error> has no method 'fill'
at Buffer.fill (buffer-browserify/index.js:558:22)
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L605
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L623
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L706
https://github.com/joyent/node/blob/master/test/simple/test-buffer.js#L719
Indeed, not all functionalities from node are covered yet. Will add them whenever possible. Feel free to submit a PR too :-)
no hurry. I just wanted to document it.
Is this report still current or has the library been superseded or something?
The report is still current. The library is functional as it is but does not implement all functionalities from node yet.
As a relative JS noob I'm wondering if it's even possible to fix writing and reading via buffer[number]
? I'm trying to use https://github.com/creationix/jsonparse with browserify and this is making it barf. If it can't be fixed here then I'll have to look at maybe detecting browserify and using something other than a Buffer
in those cases.
@GraemeF : see http://stackoverflow.com/q/1711357
@ysangkok : Ah, just as I feared. Thanks!
Ah, I just got bitten by the buf[i]
issue, too. Luckily the call is in my own code, so it's simple to replace it with buf.get(i)
for now.
I'm all about fixing the buf[i]
issue. Typed array sounds promising. However, browser support for those seem pretty crappy so I don't think that this is actually a viable solution for now, unless there is some kind of browser detection+fallback which would definitely yield bad code I fear..
@toots I'm curious to know which technique you plan to use for fixing the buf[i]
issue: __defineGetter__
, defineProperty
or others ? buf[i] = this.parent[i]
does not do the hack, right ? Have you already started something ?
FYI @substack is working on a patch for the buf[i]
issue (it was mentioned in https://github.com/dominictarr/JSONStream/pull/23#issuecomment-15019910).
Hi all,
@alexstrat I have no preference as to which technique to use, my only concerns are:
- Compatibility with a reasonable set of browsers
- Backward compatibility with node.js' original buffers (including potential boog/weird API specifics)
I have not yet started working on it but, @GraemeF : any patch for this would be much welcome and I'd try to review and merge in a timely fashion, should that happen! :-)
Here's the buf[i]
patch: https://github.com/toots/buffer-browserify/pull/14
It's really big because it unfortunately required merging SlowBuffer
with Buffer
because buf[i]
only works with SlowBuffer
but the external interface differs from Buffer
. However, all the old tests pass plus some new ones to test buf[i]
.