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

bromba

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bromba - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

83

lib/bromba.js

@@ -1,3 +0,2 @@

const async = require('async');
const asyncCache = require('async-cache');
const LRU = require('lru-cache');

@@ -12,4 +11,4 @@ const sector = require('./sector');

let index = 0 ;
for(let i = 2; i < key.byteLength; i++) {
let index = 0;
for (let i = 2; i < key.byteLength; i++) {
index *= 16;

@@ -25,11 +24,9 @@ index += key[i];

function bromba(path, { vlen, max = Infinity }) {
const cache = asyncCache({
function bromba(path, { vlen, max = 10 * 1024 * 1024}) {
const cache = new LRU({
max,
maxAge: Infinity,
stale: true,
length: s => s.size(),
load: loadSectorFromDisk,
fetchMethod: loadSectorFromDisk,
dispose: flushSector
});
let closing = false;

@@ -40,53 +37,49 @@ function nameToFile(name) {

function loadSectorFromDisk(name, fn) {
let file = nameToFile(name);
let s = sector({ vlen });
s.readFromFile(file, fn);
function loadSectorFromDisk(name) {
const file = nameToFile(name);
const s = sector({ vlen });
return s.readFromFile(file);
}
function flushSector(name, s, fn) {
let file = nameToFile(name);
s.writeToFile(file, fn);
async function flushSector(v, name) {
if (closing) {
// if we are closing all sectors are flushed already
return;
}
const file = nameToFile(name);
const s = await v;
return s.writeToFile(file);
}
function putOne(key, value, fn) {
async function putOne(key, value) {
const { name, index } = keyToLocation(key);
cache.get(name, function(err, sector) {
if (!err) {
sector.putValue(index, value);
}
fn(err);
});
const sector = await cache.fetch(name);
return sector.putValue(index, value);
}
function putMany(keys, values, fn) {
async.eachOf(keys, (k, i, fn) => putOne(k, values[i], fn), fn);
function putMany(keys, values) {
return Promise.all(keys.map((k, i) => putOne(k, values[i])));
}
function getOne(key, fn) {
async function getOne(key) {
const { name, index } = keyToLocation(key);
cache.get(name, function(err, sector) {
if(err) { return fn(err); }
fn(null, sector.getValue(index));
});
const sector = await cache.fetch(name);
return sector.getValue(index);
}
function getMany(keys, fn) {
async.map(keys, getOne, fn);
function getMany(keys) {
return Promise.all(keys.map(getOne));
}
function open(fn = () => {}) {
// nothing to do on open
fn();
function open() {
}
function close(fn = () => {}) {
async.each(
cache.keys(),
(name, fn) => flushSector(name, cache.peek(name), fn),
err => {
cache.reset();
fn(err);
}
);
async function close() {
const flushTasks = Array
.from(cache.entries())
.map(([k, v]) => flushSector(v, k));
await Promise.all(flushTasks);
closing = true;
cache.clear();
closing = false;
}

@@ -93,0 +86,0 @@

@@ -1,3 +0,2 @@

const { waterfall } = require('async');
const { writeFile, readFile, mkdir } = require('fs');
const { writeFile, readFile, mkdir } = require('fs').promises;
const { dirname } = require('path');

@@ -66,42 +65,28 @@ const { compress, uncompress } = require('snappy');

function readFromFile(file, fn) {
readFile(file, onread);
function onread(err, cbuffer) {
async function readFromFile(file) {
try {
const cbuffer = await readFile(file);
data = await uncompress(cbuffer);
dirty = false;
if (!err) {
return uncompress(cbuffer, ondata);
}
return self;
} catch(err) {
if (err.code === 'ENOENT') {
// it's OK if file does not exist yet
return fn(null, self);
return self;
}
fn(err);
throw err;
}
function ondata(err, buffer) {
if (err) {
return fn(err);
}
dirty = false;
data = buffer;
fn(err, self);
}
}
function writeToFile(file, fn = () => {}) {
async function writeToFile(file) {
if (!dirty) {
return fn(null, self);
return self;
}
dirty = false;
waterfall([
fn => mkdir(dirname(file), { recursive: true }, fn),
fn => compress(data, fn),
(b, fn) => writeFile(file, b, fn)
], err => {
if (err) {
console.error(err);
}
fn(err);
});
const [ buffer ] = await Promise.all([
compress(data),
mkdir(dirname(file), { recursive: true })
]);
await writeFile(file, buffer);
return self;
}

@@ -108,0 +93,0 @@

{
"name": "bromba",
"version": "0.0.3",
"version": "0.1.0",
"description": "Fast wasteful short buffer disk storage.",

@@ -18,10 +18,8 @@ "author": {

"dependencies": {
"async": "~2",
"async-cache": "~1",
"snappy": "^6.2.2"
"lru-cache": "^7.10.1",
"snappy": "~7"
},
"devDependencies": {
"jshint": "~2",
"tap-dot": "~2",
"tape": "~4",
"tape": "~5",
"tmp": "~0"

@@ -28,0 +26,0 @@ },

[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]
[![Dev Dependency Status][deps-dev-image]][deps-dev-url]

@@ -24,16 +23,11 @@ # bromba

// keys and values have to be Arrays of Buffer's
let keys = [2, 3, 4].map(x => Buffer.from([x]));
// keys and values have to be Arrays of Buffer's
db.putMany(keys, values, function(err) {
// for each key in an keys set corresponding value from values
});
// for each key in an keys set corresponding value from values
await db.putMany(keys, values)
db.getMany(keys, function(err, values) {
if (err) {
// something went wrong
}
// values for each key from keys
});
// values for each key from keys
const values = await db.getMany(keys);
```

@@ -45,12 +39,9 @@

[npm-image]: https://img.shields.io/npm/v/bromba.svg
[npm-image]: https://img.shields.io/npm/v/bromba
[npm-url]: https://npmjs.org/package/bromba
[travis-url]: https://travis-ci.com/pirxpilot/bromba
[travis-image]: https://img.shields.io/travis/com/pirxpilot/bromba.svg
[build-url]: https://github.com/pirxpilot/bromba/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/workflow/status/pirxpilot/bromba/check
[deps-image]: https://img.shields.io/david/pirxpilot/bromba.svg
[deps-url]: https://david-dm.org/pirxpilot/bromba
[deps-dev-image]: https://img.shields.io/david/dev/pirxpilot/bromba.svg
[deps-dev-url]: https://david-dm.org/pirxpilot/bromba?type=dev
[deps-image]: https://img.shields.io/librariesio/release/npm/bromba
[deps-url]: https://libraries.io/npm/bromba
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