Comparing version 2.2.0 to 2.2.1
export let Env, Compression, Cursor, getAddress, clearKeptObjects, setGlobalBuffer, | ||
require, arch, fs, os, tmpdir, lmdbError, path, EventEmitter, orderedBinary, MsgpackrEncoder, WeakLRUCache; | ||
require, arch, fs, os, onExit, tmpdir, lmdbError, path, EventEmitter, orderedBinary, MsgpackrEncoder, WeakLRUCache; | ||
export function setNativeFunctions(externals) { | ||
@@ -25,2 +25,3 @@ Env = externals.Env; | ||
os = externals.os; | ||
onExit = externals.onExit; | ||
} |
@@ -18,3 +18,8 @@ import { createRequire } from 'module'; | ||
setExternals({ | ||
require, arch, fs, tmpdir, path, MsgpackrEncoder, WeakLRUCache, orderedBinary, EventEmitter, os: platform(), | ||
require, arch, fs, tmpdir, path, MsgpackrEncoder, WeakLRUCache, orderedBinary, | ||
EventEmitter, os: platform(), onExit(callback) { | ||
if (process.getMaxListeners() < process.listenerCount('exit') + 8) | ||
process.setMaxListeners(process.listenerCount('exit') + 8); | ||
process.on('exit', callback); | ||
} | ||
}); | ||
@@ -21,0 +26,0 @@ export { toBufferKey as keyValueToBuffer, compareKeys, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary'; |
60
open.js
@@ -52,3 +52,3 @@ import { Compression, getAddress, require, arch, fs, path as pathModule, lmdbError, EventEmitter, MsgpackrEncoder, Env, tmpdir, os } from './external.js'; | ||
pageSize: 4096, | ||
overlappingSync: (options && options.noSync) ? false : os != 'win32', | ||
overlappingSync: (options && (options.noSync || options.readOnly)) ? false : os != 'win32', | ||
// default map size limit of 4 exabytes when using remapChunks, since it is not preallocated and we can | ||
@@ -68,28 +68,23 @@ // make it super huge. | ||
if (!exists(options.noSubdir ? pathModule.dirname(path) : path)) | ||
fs.mkdirSync(options.noSubdir ? pathModule.dirname(path) : path, { recursive: true }); | ||
if (options.compression) { | ||
let setDefault; | ||
if (options.compression == true) { | ||
if (defaultCompression) | ||
options.compression = defaultCompression; | ||
else { | ||
let compressionOptions = { | ||
threshold: 1000, | ||
dictionary: fs.readFileSync(new URL('./dict/dict.txt', | ||
import.meta.url.replace(/dist[\\\/]index.cjs$/, ''))), | ||
getValueBytes: makeReusableBuffer(0), | ||
}; | ||
defaultCompression = options.compression = new Compression(compressionOptions); | ||
Object.assign(defaultCompression, compressionOptions); | ||
} | ||
} else { | ||
let compressionOptions = Object.assign({ | ||
threshold: 1000, | ||
dictionary: fs.readFileSync(new URL('./dict/dict.txt', import.meta.url.replace(/dist[\\\/]index.cjs$/, ''))), | ||
getValueBytes: makeReusableBuffer(0), | ||
}, options.compression); | ||
options.compression = new Compression(compressionOptions); | ||
Object.assign(options.compression, compressionOptions); | ||
} | ||
fs.mkdirSync(options.noSubdir ? pathModule.dirname(path) : path, { recursive: true } | ||
); | ||
function makeCompression(compressionOptions) { | ||
if (compressionOptions instanceof Compression) | ||
return compressionOptions; | ||
let useDefault = typeof compressionOptions != 'object'; | ||
if (useDefault && defaultCompression) | ||
return defaultCompression; | ||
compressionOptions = Object.assign({ | ||
threshold: 1000, | ||
dictionary: fs.readFileSync(new URL('./dict/dict.txt', import.meta.url.replace(/dist[\\\/]index.cjs$/, ''))), | ||
getValueBytes: makeReusableBuffer(0), | ||
}, compressionOptions); | ||
let compression = Object.assign(new Compression(compressionOptions), compressionOptions); | ||
if (useDefault) | ||
defaultCompression = compression; | ||
return compression; | ||
} | ||
if (options.compression) | ||
options.compression = makeCompression(options.compression); | ||
let flags = | ||
@@ -112,3 +107,3 @@ (options.overlappingSync ? 0x1000 : 0) | | ||
let rc = env.open(options, flags, jsFlags); | ||
if (rc) | ||
if (rc) | ||
lmdbError(rc); | ||
@@ -125,11 +120,6 @@ let maxKeySize = env.getMaxKeySize(); | ||
if (dbOptions.compression instanceof Compression) { | ||
// do nothing, already compression object | ||
} else if (dbOptions.compression && typeof dbOptions.compression == 'object') | ||
dbOptions.compression = new Compression(Object.assign({ | ||
threshold: 1000, | ||
dictionary: fs.readFileSync(require.resolve('./dict/dict.txt')), | ||
}), dbOptions.compression); | ||
else if (options.compression && dbOptions.compression !== false) | ||
if (options.compression && dbOptions.compression !== false && typeof dbOptions.compression != 'object') | ||
dbOptions.compression = options.compression; // use the parent compression if available | ||
else if (dbOptions.compression) | ||
dbOptions.compression = makeCompression(dbOptions.compression); | ||
@@ -136,0 +126,0 @@ if (dbOptions.dupSort && (dbOptions.useVersions || dbOptions.cache)) { |
{ | ||
"name": "lmdb", | ||
"author": "Kris Zyp", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Simple, efficient, scalable, high-performance LMDB interface", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
15
read.js
@@ -39,12 +39,17 @@ import { RangeIterable } from './util/RangeIterable.js'; | ||
if (this.lastSize > bytes.maxLength) { | ||
// this means we 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 (this.lastSize === 0xffffffff) | ||
return; | ||
if (returnNullWhenBig && this.lastSize >= 0x10000) | ||
return null; | ||
/*if (returnNullWhenBig && this.lastSize >= 0x10000) | ||
// used by getBinary to indicate it should create a dedicated buffer to receive this | ||
return null;*/ | ||
if (this.lastSize >= 0x10000 && !compression && this.db.getSharedByBinary) { | ||
if (this.lastShared) | ||
// 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) // we have to detach the last one, or else could crash due to two buffers pointing at same location | ||
env.detachBuffer(this.lastShared.buffer) | ||
return this.lastShared = this.db.getSharedByBinary(this.writeKey(id, keyBytes, 0)); | ||
} | ||
// grow our shared/static buffer to accomodate the size of the data | ||
bytes = this._allocateGetBuffer(this.lastSize); | ||
// and try again | ||
this.lastSize = this.db.getByBinary(this.writeKey(id, keyBytes, 0)); | ||
@@ -78,2 +83,4 @@ } | ||
getBinary(id) { | ||
let fastBuffer = this.getBinaryFast(id); | ||
return fastBuffer && Uint8ArraySlice.call(fastBuffer, 0, this.lastSize);/* | ||
let bytesToRestore, compressionBytesToRestore; | ||
@@ -108,3 +115,3 @@ try { | ||
} | ||
} | ||
}*/ | ||
}, | ||
@@ -111,0 +118,0 @@ get(id) { |
13
write.js
@@ -1,2 +0,2 @@ | ||
import { getAddress } from './external.js'; | ||
import { getAddress, onExit } from './external.js'; | ||
import { when } from './util/when.js'; | ||
@@ -73,3 +73,13 @@ var backpressureArray; | ||
var unwrittenResolution = nextResolution; | ||
let needToRegisterOnExit = overlappingSync; | ||
function writeInstructions(flags, store, key, value, version, ifVersion) { | ||
if (needToRegisterOnExit) { | ||
needToRegisterOnExit = false; | ||
if (onExit) { | ||
onExit(() => { | ||
if (env.sync) // if we have already closed the env, this will be null | ||
env.sync(); | ||
}) | ||
} | ||
} | ||
let writeStatus; | ||
@@ -802,2 +812,3 @@ let targetBytes, position, encoder; | ||
} | ||
env.sync = null; | ||
}, | ||
@@ -804,0 +815,0 @@ on(event, callback) { |
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
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 37 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
20400330
162
5118
43