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

binary encoding vs. asBuffer #83

Closed
timkuijsten opened this issue Feb 14, 2016 · 2 comments
Closed

binary encoding vs. asBuffer #83

timkuijsten opened this issue Feb 14, 2016 · 2 comments

Comments

@timkuijsten
Copy link
Contributor

I'm wondering what the exact purpose of the asBuffer option is (and it's cousins keyAsBuffer and valueAsBuffer). To me it feels redundant since one can use keyEncoding binary and/or valueEncoding binary.

I wonder what to do when using IndexedDB as a backend which has support for native JS types as values and supports some different types for keys (Level/level-js#48). I know in level.js they even have a raw option. I can't really tell the difference between encoding, asBuffer and raw.

/cc @nolanlawson

@vweevers
Copy link
Member

I'm wondering what the exact purpose of the asBuffer option is (and it's cousins keyAsBuffer and valueAsBuffer).

The asBuffer option tells the store to fetch data as a Buffer, and avoid unnecessary conversion. Stores like leveldown have the ability to return either a Buffer or string, both sourced from the same byte array. See encoding format for more.

To me it feels redundant since one can use keyEncoding binary and/or valueEncoding binary.

The binary encoding is just one of the encodings (which is user-specified) that result in asBuffer: true (which is derived from the encoding).

I wonder what to do when using IndexedDB as a backend which has support for native JS types as values and supports some different types for keys (Level/level-js#48)

TBD, to be discussed elsewhere.

I know in level.js they even have a raw option.

IMO the non-standard raw option should be removed from level.js. And if asBuffer is false, level.js should return the value as-is. Then, by using the identity encoding, one can achieve the same effect as raw: true.

@vweevers
Copy link
Member

See also Level/level-js#58

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

2 participants