blockstore: additional options and create function
This commit is contained in:
parent
8748e4dd2d
commit
11af5456ce
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user