Level / memdown

In-memory abstract-leveldown store for Node.js and browsers.
MIT License
287 stars 37 forks source link

Buffers in the browser #183

Closed ghost closed 5 years ago

ghost commented 5 years ago

This could be just a 'me' problem, but I ran into a very difficult to debug issue due to my misunderstanding of how memdown stores worked in the browser. I figured since it used Buffers for Keys and Values, that I needed a browser Buffer implementation. What ended up happening was I'd put buffer values created with this https://github.com/feross/buffer, then when I would read them, it would presumably return another buffer format, the contents of which were completely different. Running it in node and switching to regular node buffers worked fine.

Can I get a clarification of how buffers should be consumed in the browser?

vweevers commented 5 years ago

memdown (or the app that it is used in) should be be bundled for browsers using browserify, webpack or similar. Those bundlers will replace usage of Buffer with https://github.com/feross/buffer, so that code is universal (works the same in node and browsers).

vweevers commented 5 years ago

Feel free to reopen or comment here if you have additional questions. Level/browserify-starter might be helpful. It bundles level-js rather than memdown, but the process is the same.