-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
genericize test suite to make sense in browser #2
Comments
|
Is it okay to abstract away the ability to store native data types so that On Tue, Apr 30, 2013 at 12:03 PM, Julian Gruber notifications@github.comwrote:
|
I prefer having only strings and buffers...That could cause frustrations and unexpected results when having to sync. It would be cool if all leveldb implementations behaved the same, so we have a solid base. |
Agree with @juliangruber. There is a lot of code sitting above that could make assumptions on storage. I am not sure what having an option is going to by you as all the modules above are going to expect string buffer? |
trying to make Buffer work in the browser doesn't make sense because there today I believe buffer-browserify is just a bunch of sugar on top of On Tue, Apr 30, 2013 at 1:24 PM, Anton Whalley notifications@github.comwrote:
|
more thoughts:
On Tue, Apr 30, 2013 at 1:42 PM, Max Ogden max@maxogden.com wrote:
|
@maxogden for the tests we just need And I'm working on mux-demux + redis-protocol-stream btw. |
@maxogden so this means that |
yup I think that's the current api. |
LevelUP already does the conversion to/from Buffers and Strings under the assumption that that's all that LevelDOWN handles, even though LevelDOWN has a |
(re-commented because email reply broke formatting because github has a bug or something) Here are my goals for a storage lib for browsers that syncs with leveldb in
So, if we use Buffer it throws away the speed of Typed Arrays. If we use One solution is that I can put |
For my part I'm OK with having branches in the tests to deal with browser environments as a separate case. I don't know much about browserify's Buffer implementation but from what I've heard it does sound like a poor choice. Although I wonder whether that means that this is something to be fixed there rather than here? Or is that impossible? This will add complexity to LevelUP though but we can at least feature-detect on init and replace the default Buffer conversion functions with whatever's more appropriate. |
Good question, there is toots/buffer-browserify#8 but it has no reply from the maintainer. Here are the issues I'm aware of in wrapping ArrayBuffers in the Buffer API (could be more):
|
also cc smart people for moar input @isaacs @thisandagain |
@maxogden on the indexeddb support In mobile scenarios we are using localstorage because of poor mobile support for indexeddb and this suffices for certain use cases. There is also work progressing on integrating IOS and Android ports of leveldb which will be accessed through browser based javascript via phonegap. These storage engines will no doubt have features (more likely idiosyncrasies) that they will bring and I wouldn't expect abstract-leveldown to cater for them too much. Maybe there is an elegant solution that can resolve this problem but I thought it would be better to air my concerns. |
Agreed that IDB won't be the only backend, but it will probably be the only one where low level performance matters. I think the behavior of leveldown right now (only strings and buffers) is too limiting. If we allow other JS types to exist but still allow the simpler case of strings + buffers then we should be able to have the test suite support lots of use cases. |
So, we just need leveldown to handle the encoding - or to expose some option so to tell levelup not to do anything before passing it to leveldown. |
ok, level.js, abstract-leveldown and leveldown all pass the same tests. I decided to just roll with strings and binary for now and to add some browser specific tests for other data types later |
FYI @maxogden - I'm pretty sure native-buffer-browserify solves all the problems with Once Thoughts? |
@feross sounds good. just curious as to what you mean by " |
Streams expect |
This has been my biggest annoyance with |
@feross hmm, we should probably have the browser-built in do can you post a gist of something that seems reasonable but isn't working? |
All readable-stream works only in object mode in the browser with bops buffers. |
for modules like if you want to use other types of typed arrays then native-buffer-browserify isn't ideal, but for the majority of use cases it looks like a nice solution. I still don't really understand your grievances with bops + streams, I guess I haven't ever run into those issues. i can't think of a stream that I've used in a browser that rejects non |
@maxogden @mcollina is probably talking about https://npm.im/readable-stream core node has things like |
Thanks @dominictarr, that was what I was saying. I'm guessing that if we want to be bops-compliant, we should have a fork for readable-stream to something like readable-stream-bops. |
@mcollina I was hoping that by backing the browserify |
@feross exactly. The problem is we have tons of stuff built on bops and typed arrays. How can we support both styles in levelup (and others)? |
Buffer-browserify might not make as much sense here, as indexeddb can natively store any JS type except Object. So if you give it a typed array it can store it without any serialization, but I'm not sure about what would happen if you gave it one of the hacked uint8arrays from buffer-browserify Sent from my iPhone
|
Remember that the Buffer API has toArrayBuffer() coming in 0.11 which Not sure what makes sense for level here, but in general I think it would On Monday, November 25, 2013, Max Ogden wrote:
Feross |
It's actually pretty easy to support both styles going forward. The var bopsBuffer = bops.from('hey there!') // returns Uint8Array
var realBuffer = new Buffer(bopsBuffer) // returns Uint8Array augmented with Buffer methods, treat it like a node Buffer! |
For any library that needs to work with the streams2 implementation in browserify, it's important to use a real If you really want to keep using |
browserify v3 is very soon going to start using Uint8Arrays for Buffer by way of native-buffer-browserify. |
this almost passes all the leveldown tests (except iterators, havent worked on those yet): https://github.com/maxogden/level.js
there are two fundamental differences though:
so, is it cool if I add a bunch of conditional browser specific stuff to the test suite? is there a better 'paradigm' we could use for return value checking?
The text was updated successfully, but these errors were encountered: