You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Specification
The
ArrayBuffertype is more generalised in the JS ecosystem. The DB right now focuses on taking Node Buffers.Node buffers can be converted to
ArrayBuffereasily, andArrayBuffercan 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
asBufferhas to be turned false.I'm not sure how this would work with
keyEncodingandvalueEncodingthat we have set to'binary'.Our
rawis also specifying that we would getBuffer, would that mean we instead say that we returnArrayBufferinstead, and with keys it would bestring | 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
bufferlibrary. This will mean that any usage ofimport { Buffer } from 'buffer';will be resolved by feross/buffer first though, so one should beware of that.Note that all Node
BufferisUint8Arraywhich isArrayBuffer.If something supports
ArrayBuffer, they would supportUint8ArrayandBufferat the same time.One benefit would be integration of js-id MatrixAI/js-id#1 can be simplified since
IdasUint8Arraycan be stored directly in the DB without first wrapping them asBuffer.Additional context
Tasks
ArrayBuffercompatibility in leveldbArrayBufferin DB without losingBuffersupportstring | Bufferwithstring | ArrayBufferfor keys, but retainBufferon returned output.domainPathwith UsebufferWrapto supportArrayBuffer,Uint8ArrayandBuffer#3 (comment)this.crypto.keyto be assumed to beArrayBuffertoArrayBufferto an explicit slice copy of all possible instances ofArrayBuffertypefromArrayBufferis still useful since we returnBuffer.serializeanddeserializeto useArrayBufferandTextEncoderandTextDecoderwhich can do theutf-8encoding/decoding.deserializeandserializemight need to change.Uint8ArrayandArrayBufferusage, and ensure that slice-copying is working.