diff --git a/lib/blockstore/file.js b/lib/blockstore/file.js index 1db803d2..9b176575 100644 --- a/lib/blockstore/file.js +++ b/lib/blockstore/file.js @@ -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; diff --git a/lib/blockstore/index.js b/lib/blockstore/index.js index 77bf9715..b8e4c634 100644 --- a/lib/blockstore/index.js +++ b/lib/blockstore/index.js @@ -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; diff --git a/lib/blockstore/level.js b/lib/blockstore/level.js index bc965c87..83b9db7d 100644 --- a/lib/blockstore/level.js +++ b/lib/blockstore/level.js @@ -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 }); }