- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Description
Specification
The ArrayBuffer type is more generalised in the JS ecosystem. The DB right now focuses on taking Node Buffers.
Node buffers can be converted to ArrayBuffer easily, and ArrayBuffer can be wrapped in Node buffers.
According to this comment: Level/level-js#34 (comment) it is possible to use ArrayBuffers directly in leveldb, it just not documented.
It says that the asBuffer has to be turned false.
I'm not sure how this would work with keyEncoding and valueEncoding that we have set to 'binary'.
Our raw is also specifying that we would get Buffer, would that mean we instead say that we return ArrayBuffer instead, and with keys it would be string | ArrayBuffer?
Furthermore this would impact js-encryptedfs, so it's worthwhile to explore the implications of this.
The primary reason to do this would be cross-platform compatibility for mobile platforms that may not have the Node buffer.
The alternative would be use https://github.com/feross/buffer everywhere as a dependency so that way everything just uses the buffer library. This will mean that any usage of  import { Buffer } from 'buffer'; will be resolved by feross/buffer first though, so one should beware of that.
Note that all Node Buffer is Uint8Array which is ArrayBuffer.
If something supports ArrayBuffer, they would support Uint8Array and Buffer at the same time.
One benefit would be integration of js-id MatrixAI/js-id#1 can be simplified since Id as Uint8Array can be stored directly in the DB without first wrapping them as Buffer.
Additional context
Tasks
-  - Investigate 
ArrayBuffercompatibility in leveldb -  - Investigate to what extent can we enable compatibility with 
ArrayBufferin DB without losingBuffersupport -  - Replace all uses of 
string | Bufferwithstring | ArrayBufferfor keys, but retainBufferon returned output.- fix 
domainPathwith UsebufferWrapto supportArrayBuffer,Uint8ArrayandBuffer#3 (comment) - this incorporates the Robustness principle: https://en.wikipedia.org/wiki/Robustness_principle
 
 - fix 
 -  - Change 
this.crypto.keyto be assumed to beArrayBuffer -  - Change 
toArrayBufferto an explicit slice copy of all possible instances ofArrayBuffertype -  - The 
fromArrayBufferis still useful since we returnBuffer. -  - Change 
serializeanddeserializeto useArrayBufferandTextEncoderandTextDecoderwhich can do theutf-8encoding/decoding. -  - Check if PK is using any of the utility functions here, some uses of 
deserializeandserializemight need to change. - - Ensure that most signatures are still compatible
 -  - Update all tests to include 
Uint8ArrayandArrayBufferusage, and ensure that slice-copying is working. - - Check that there's no performance regression on the benchmarks