blockstore: additional options and create function

This commit is contained in:
Braydon Fuller 2019-03-07 10:55:20 -08:00
parent 8748e4dd2d
commit 11af5456ce
No known key found for this signature in database
GPG Key ID: F24F232D108B3AD4
3 changed files with 41 additions and 9 deletions

View File

@ -37,9 +37,14 @@ class FileBlockStore extends AbstractBlockStore {
assert(isAbsolute(options.location), 'Location not absolute.');
this.location = options.location;
this.indexLocation = resolve(this.location, './index');
this.db = bdb.create({
location: resolve(this.location, './index')
location: this.indexLocation,
cacheSize: options.cacheSize,
compression: false
});
this.maxFileLength = options.maxFileLength || 128 * 1024 * 1024;
this.network = Network.primary;

View File

@ -6,10 +6,37 @@
'use strict';
const {join} = require('path');
const AbstractBlockStore = require('./abstract');
const LevelBlockStore = require('./level');
const FileBlockStore = require('./file');
/**
* @module blockstore
*/
exports.AbstractBlockStore = require('./abstract');
exports.FileBlockStore = require('./file');
exports.LevelBlockStore = require('./level');
exports.create = (options) => {
const location = join(options.prefix, 'blocks');
if (options.memory) {
return new LevelBlockStore({
network: options.network,
logger: options.logger,
location: location,
cacheSize: options.cacheSize,
memory: options.memory
});
}
return new FileBlockStore({
network: options.network,
logger: options.logger,
location: location,
cacheSize: options.cacheSize
});
};
exports.AbstractBlockStore = AbstractBlockStore;
exports.FileBlockStore = FileBlockStore;
exports.LevelBlockStore = LevelBlockStore;

View File

@ -6,9 +6,7 @@
'use strict';
const {isAbsolute, resolve} = require('path');
const bdb = require('bdb');
const assert = require('bsert');
const AbstractBlockStore = require('./abstract');
const layout = require('./layout');
const {types} = require('./common');
@ -29,11 +27,13 @@ class LevelBlockStore extends AbstractBlockStore {
constructor(options) {
super();
assert(isAbsolute(options.location), 'Location not absolute.');
this.location = options.location;
this.db = bdb.create({
location: resolve(this.location, './index')
location: this.location,
cacheSize: options.cacheSize,
compression: false,
memory: options.memory
});
}