Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with browserify buffers #10

Closed
GraemeF opened this issue Oct 21, 2012 · 6 comments
Closed

Not working with browserify buffers #10

GraemeF opened this issue Oct 21, 2012 · 6 comments

Comments

@GraemeF
Copy link

GraemeF commented Oct 21, 2012

I'm trying to use jsonparse (via @dominictarr's JSONStream) with browserify and, since buffer-browserify doesn't (and apparently can't) support buf[index] it doesn't work.

JSONStream already detects whether Buffer is available so maybe that could detect browserify buffers and choose not to use them, but maybe it would be better if jsonparse could deal with it itself?

What do y'all think?

@dominictarr
Copy link

hmm, this is strange, I know @substack uses JSONStream a lot, in browserify.

@GraemeF can you post a script to reproduce?

@GraemeF
Copy link
Author

GraemeF commented Oct 21, 2012

Good to hear, probably just me then. But it is definitely strange so here's the whole story... It works fine in Chrome and Firefox but I'm running end-to-end tests using zombie and it's there that I see the problem.

I found that using a browserify Buffer makes the existing tests fail in the same way (or maybe in a different way that happens to look the same 😊 ), so that's an easy way to repro: GraemeF/JSONStream@d4e1cb5

@dominictarr
Copy link

right, so this is a bug in zombie then.

@GraemeF
Copy link
Author

GraemeF commented Oct 21, 2012

I don't think so; with the original code in the browser I'm seeing that Buffer is undefined so it hits the other code path at https://github.com/dominictarr/JSONStream/blob/master/index.js#L75 and works.

If you have code that does a require('buffer').Buffer in the browser then browserify will substitute it and then the failing path will be taken. I think zombie just happens to have the right conditions to make it hit the other path and fail.

Anyway, by explaining it I think I now understand the problem sufficiently enough to make a pull request (for JSONStream not jsonparse; sorry to hijack your issues list @creationix - I wasn't clear where the fix would be most appropriate until now!).

@creationix
Copy link
Owner

Why not just set the encoding to always use strings? In node you can choose between Buffer instances and strings. I'm sure browserify has this same option. (If it doesn't it should and it's easy to implement)

@GraemeF
Copy link
Author

GraemeF commented Oct 29, 2012

@creationix - that sounds plausible, I'll take a look. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants