Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lmdb

Package Overview
Dependencies
Maintainers
3
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lmdb - npm Package Compare versions

Comparing version 2.3.0-beta to 2.3.0-beta2

2

open.js

@@ -11,3 +11,3 @@ import { Compression, getAddress, require, arch, fs, path as pathModule, lmdbError, EventEmitter, MsgpackrEncoder, Env, Dbi, tmpdir, os, native } from './external.js';

if (globalThis.__lmdb_envs__)
setEnvsPointer(globalThis.__lmdb_envs__());
setEnvsPointer(globalThis.__lmdb_envs__);
else

@@ -14,0 +14,0 @@ globalThis.__lmdb_envs__ = getEnvsPointer();

{
"name": "lmdb",
"author": "Kris Zyp",
"version": "2.3.0-beta",
"version": "2.3.0-beta2",
"description": "Simple, efficient, scalable, high-performance LMDB interface",

@@ -56,4 +56,3 @@ "license": "MIT",

"prepare": "rollup -c",
"before-publish": "rollup -c && prebuildify-ci download && prebuildify --napi --target 16.14.0 --enable_v8=false && prebuildify --target 16.14.0",
"before-publish-with-fast": "rollup -c && prebuildify-ci download && prebuildify --napi && set ENABLE_FAST_API_CALLS=true&& prebuildify --target 16.14.0",
"before-publish": "rollup -c && prebuildify-ci download && prebuildify --target 16.14.0 && set ENABLE_V8_FUNCTIONS=false&& prebuildify --napi --target 16.14.0",
"prebuild-libc": "prebuildify --napi --tag-libc --target 16.14.0",

@@ -60,0 +59,0 @@ "prebuildify": "prebuildify",

import { RangeIterable } from './util/RangeIterable.js';
import { getAddress, Cursor, Txn, orderedBinary, native } from './external.js';
import { saveKey } from './keys.js';
const { lmdbError, getByBinary, detachBuffer, setGlobalBuffer, prefetch, iterate, position: doPosition, resetTxn, getCurrentValue, getStringByBinary, getSharedByBinary } = native;
const { lmdbError, getByBinary, detachBuffer, setGlobalBuffer, prefetch, iterate, position: doPosition, resetTxn, getCurrentValue, getCurrentShared, getStringByBinary, getSharedByBinary } = native;
const ITERATOR_DONE = { done: true, value: undefined };

@@ -15,3 +15,3 @@ const Uint8ArraySlice = Uint8Array.prototype.slice;

}) {
let readTxn, readTxnRenewed, returnNullWhenBig = false;
let readTxn, readTxnRenewed, asSafeBuffer = false;
let renewId = 1;

@@ -33,3 +33,3 @@ Object.assign(LMDBStore.prototype, {

(env.writeTxn || (readTxnRenewed ? readTxn : renewReadTxn(this)));
let rc = this.lastSize = getByBinary.call(this, this.dbAddress, this.writeKey(id, keyBytes, 0));
let rc = this.lastSize = getByBinary(this.dbAddress, this.writeKey(id, keyBytes, 0));
if (rc < 0) {

@@ -51,16 +51,50 @@ if (rc == -30798) // MDB_NOTFOUND

// this means the target buffer wasn't big enough, so the get failed to copy all the data from the database, need to either grow or use special buffer
if (returnNullWhenBig && this.lastSize > NEW_BUFFER_THRESHOLD)
// used by getBinary to indicate it should create a dedicated buffer to receive this
return null;
if (this.lastSize > NEW_BUFFER_THRESHOLD && !compression) {
// for large binary objects, cheaper to make a buffer that directly points at the shared LMDB memory to avoid copying a large amount of memory, but only for large data since there is significant overhead to instantiating the buffer
if (this.lastShared && detachBuffer) // we have to detach the last one, or else could crash due to two buffers pointing at same location
detachBuffer(this.lastShared.buffer)
return this.lastShared = getSharedByBinary(this.dbAddress, this.writeKey(id, keyBytes, 0));
return this._returnLargeBuffer(
() => getByBinary(this.dbAddress, this.writeKey(id, keyBytes, 0)),
() => getSharedByBinary(this.dbAddress, this.writeKey(id, keyBytes, 0)));
}
bytes.length = this.lastSize;
return bytes;
},
_returnLargeBuffer(getFast, getShared) {
let bytes;
let compression = this.compression;
if (asSafeBuffer && this.lastSize > NEW_BUFFER_THRESHOLD) {
// used by getBinary to indicate it should create a dedicated buffer to receive this
let bytesToRestore
try {
if (compression) {
bytesToRestore = compression.getValueBytes;
let dictionary = compression.dictionary || [];
let dictLength = (dictionary.length >> 3) << 3;// make sure it is word-aligned
bytes = makeReusableBuffer(this.lastSize);
compression.setBuffer(bytes, this.lastSize, dictionary, dictLength);
compression.getValueBytes = bytes;
} else {
bytesToRestore = getValueBytes;
setGlobalBuffer(bytes = getValueBytes = makeReusableBuffer(this.lastSize));
}
getFast();
} finally {
if (compression) {
let dictLength = (compression.dictionary.length >> 3) << 3;
compression.setBuffer(bytesToRestore, bytesToRestore.maxLength, compression.dictionary, dictLength);
compression.getValueBytes = bytesToRestore;
} else {
setGlobalBuffer(bytesToRestore);
getValueBytes = bytesToRestore;
}
}
// grow our shared/static buffer to accomodate the size of the data
bytes = this._allocateGetBuffer(this.lastSize);
// and try again
this.lastSize = getByBinary.call(this, this.dbAddress, this.writeKey(id, keyBytes, 0));
return bytes;
}
if (this.lastSize > NEW_BUFFER_THRESHOLD && !compression) {
// for large binary objects, cheaper to make a buffer that directly points at the shared LMDB memory to avoid copying a large amount of memory, but only for large data since there is significant overhead to instantiating the buffer
if (this.lastShared && detachBuffer) // we have to detach the last one, or else could crash due to two buffers pointing at same location
detachBuffer(this.lastShared.buffer);
return this.lastShared = getShared();
}
// grow our shared/static buffer to accomodate the size of the data
bytes = this._allocateGetBuffer(this.lastSize);
// and try again
getFast();
bytes.length = this.lastSize;

@@ -87,37 +121,12 @@ return bytes;

}
bytes.isShared = true;
return bytes;
},
getBinary(id) {
let bytesToRestore;
try {
returnNullWhenBig = true;
asSafeBuffer = true;
let fastBuffer = this.getBinaryFast(id);
if (fastBuffer === null) {
if (this.compression) {
bytesToRestore = this.compression.getValueBytes;
let dictionary = this.compression.dictionary || [];
let dictLength = (dictionary.length >> 3) << 3;// make sure it is word-aligned
let bytes = makeReusableBuffer(this.lastSize);
this.compression.setBuffer(bytes, this.lastSize, dictionary, dictLength);
this.compression.getValueBytes = bytes;
} else {
bytesToRestore = getValueBytes;
setGlobalBuffer(getValueBytes = makeReusableBuffer(this.lastSize));
}
return this.getBinaryFast(id);
}
return fastBuffer && Uint8ArraySlice.call(fastBuffer, 0, this.lastSize);
return fastBuffer && (fastBuffer.isShared ? Uint8ArraySlice.call(fastBuffer, 0, this.lastSize) : fastBuffer);
} finally {
returnNullWhenBig = false;
if (bytesToRestore) {
if (this.compression) {
let compression = this.compression;
let dictLength = (compression.dictionary.length >> 3) << 3;
compression.setBuffer(bytesToRestore, bytesToRestore.maxLength, compression.dictionary, dictLength);
compression.getValueBytes = bytesToRestore;
} else {
setGlobalBuffer(bytesToRestore);
getValueBytes = bytesToRestore;
}
}
asSafeBuffer = false;
}

@@ -363,12 +372,18 @@ },

if (lastSize > bytes.maxLength) {
bytes = store._allocateGetBuffer(lastSize);
let rc = getCurrentValue(cursorAddress);
if (rc < 0)
lmdbError(count);
}
bytes.length = lastSize;
store.lastSize = lastSize;
asSafeBuffer = store.encoding == 'binary';
try {
bytes = store._returnLargeBuffer(
() => getCurrentValue(cursorAddress),
() => getCurrentShared(cursorAddress)
);
} finally {
asSafeBuffer = false;
}
} else
bytes.length = lastSize;
if (store.decoder) {
value = store.decoder.decode(bytes, lastSize);
} else if (store.encoding == 'binary')
value = Uint8ArraySlice.call(bytes, 0, lastSize);
value = bytes.isShared ? Uint8ArraySlice.call(bytes, 0, lastSize) : bytes;
else {

@@ -375,0 +390,0 @@ value = bytes.toString('utf8', 0, lastSize);

[![license](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE)
[![npm version](https://img.shields.io/npm/v/lmdb.svg?style=flat-square)](https://www.npmjs.org/package/lmdb)
[![npm downloads](https://img.shields.io/npm/dw/lmdb-store)](https://www.npmjs.org/package/lmdb)
[![npm downloads](https://img.shields.io/npm/dw/lmdb)](https://www.npmjs.org/package/lmdb)
[![get](https://img.shields.io/badge/get-8.5%20MOPS-yellow)](README.md)

@@ -5,0 +5,0 @@ [![put](https://img.shields.io/badge/put-1.7%20MOPS-yellow)](README.md)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc