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

datastore-level

Package Overview
Dependencies
Maintainers
3
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datastore-level - npm Package Compare versions

Comparing version 0.14.0 to 0.14.1

test/fixtures/test-level-iterator-destroy.js

15

CHANGELOG.md

@@ -0,1 +1,16 @@

<a name="0.14.1"></a>
## [0.14.1](https://github.com/ipfs/js-datastore-level/compare/v0.14.0...v0.14.1) (2020-01-14)
### Bug Fixes
* leveldb iterator memory leak ([#26](https://github.com/ipfs/js-datastore-level/issues/26)) ([e503c1a](https://github.com/ipfs/js-datastore-level/commit/e503c1a)), closes [/github.com/Level/leveldown/blob/d3453fbde4d2a8aa04d9091101c25c999649069b/binding.cc#L545](https://github.com//github.com/Level/leveldown/blob/d3453fbde4d2a8aa04d9091101c25c999649069b/binding.cc/issues/L545)
### Performance Improvements
* optimize prefix search ([#25](https://github.com/ipfs/js-datastore-level/issues/25)) ([8efa812](https://github.com/ipfs/js-datastore-level/commit/8efa812))
<a name="0.14.0"></a>

@@ -2,0 +17,0 @@ # [0.14.0](https://github.com/ipfs/js-datastore-level/compare/v0.13.0...v0.14.0) (2019-11-29)

3

package.json
{
"name": "datastore-level",
"version": "0.14.0",
"version": "0.14.1",
"description": "Datastore implementation with level(up|down) backend",

@@ -54,2 +54,3 @@ "leadMaintainer": "Pedro Teixeira <pedro@protocol.ai>",

"Alan Shaw <alan.shaw@protocol.ai>",
"Carson Farmer <carson.farmer@gmail.com>",
"David Dias <daviddias.p@gmail.com>",

@@ -56,0 +57,0 @@ "Friedel Ziegelmayer <dignifiedquire@gmail.com>",

@@ -39,2 +39,8 @@ # js-datastore-level

The type definitions for this package are available on http://definitelytyped.org/. To install just use:
```sh
$ npm install -D @types/datastore-level
```
## Usage

@@ -85,2 +91,2 @@

[MIT](LICENSE)
[MIT](LICENSE)

@@ -108,8 +108,19 @@ 'use strict'

const opts = {
keys: true,
values: values,
keyAsBuffer: true
}
// Let the db do the prefix matching
if (q.prefix != null) {
const prefix = q.prefix.toString()
// Match keys greater than or equal to `prefix` and
opts.gte = prefix
// less than `prefix` + \xFF (hex escape sequence)
opts.lt = prefix + '\xFF'
}
let it = levelIteratorToIterator(
this.db.db.iterator({
keys: true,
values: values,
keyAsBuffer: true
})
this.db.iterator(opts)
)

@@ -125,6 +136,2 @@

if (q.prefix != null) {
it = filter(it, e => e.key.toString().startsWith(q.prefix))
}
if (Array.isArray(q.filters)) {

@@ -156,3 +163,8 @@ it = q.filters.reduce((it, f) => filter(it, f), it)

if (err) return reject(err)
if (key == null) return resolve({ done: true })
if (key == null) {
return li.end(err => {
if (err) return reject(err)
resolve({ done: true })
})
}
resolve({ done: false, value: { key, value } })

@@ -159,0 +171,0 @@ })

@@ -13,2 +13,3 @@ /* eslint-env mocha */

const { promisify } = require('util')
const childProcess = require('child_process')

@@ -72,2 +73,31 @@ const LevelStore = require('../src')

})
// The `.end()` method MUST be called on LevelDB iterators or they remain open,
// leaking memory.
//
// This test exposes this problem by causing an error to be thrown on process
// exit when an iterator is open AND leveldb is not closed.
//
// Normally when leveldb is closed it'll automatically clean up open iterators
// but if you don't close the store this error will occur:
//
// > Assertion failed: (ended_), function ~Iterator, file ../binding.cc, line 546.
//
// This is thrown by a destructor function for iterator objects that asserts
// the iterator has ended before cleanup.
//
// https://github.com/Level/leveldown/blob/d3453fbde4d2a8aa04d9091101c25c999649069b/binding.cc#L545
it('should not leave iterators open and leak memory', (done) => {
const cp = childProcess.fork(`${__dirname}/fixtures/test-level-iterator-destroy`, { stdio: 'pipe' })
let out = ''
cp.stdout.on('data', d => { out += d })
cp.stderr.on('data', d => { out += d })
cp.on('exit', code => {
expect(code).to.equal(0)
expect(out).to.not.include('Assertion failed: (ended_)')
done()
})
})
})
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