toots / buffer-browserify

node's buffer module, but for the browser.
MIT License
52 stars 33 forks source link

buf[i] not working sometimes #22

Open andrewrk opened 11 years ago

andrewrk commented 11 years ago

Causing zlib-browserify to be broken: https://github.com/brianloveswords/zlib-browserify/issues/6

To produce the issue:

  1. Clone this gist
  2. browserify test.js >out.js
  3. Copy out.js into jsbeautifier.org and then paste back into out.js
  4. Add a debugger statement like this:
                        debugger
                        a.C = l[k++];
                        a.D = l[k++];
                        (31 !== a.C || 139 !== a.D) && m(Error("invalid file signature:", a.C, a.D));
  1. run in the browser

You will notice that l is a Buffer and l[0] is yielding undefined when it should yield 31. Note also that l.parent[0] works.

andrewrk commented 11 years ago

@substack might be interested to see this.

terinjokes commented 11 years ago

I've found that an implementation of a streaming Boyer-Moore-Horspool search streamsearch breaks because of this. Seems pretty egregious as it's a break from the Node API.

andrewrk commented 11 years ago

@terinjokes for what it's worth, I think I got around the issue by using https://github.com/chrisdickinson/bops

but even then there was an issue I had to work around: https://github.com/chrisdickinson/bops/pull/7

terinjokes commented 11 years ago

This actually looks fixed in HEAD, but hasn't been pulled into a newer version of insert-module-globals.