Skip to content

Commit

Permalink
slight refactor of default options
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Jun 27, 2017
1 parent c455e0e commit 42ee0e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/default-options-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module.exports = {
fs: require('datastore-level'),
sharding: false,
lock: 'memory',
fsOptions: {
db: require('level-js')
},
Expand Down
5 changes: 3 additions & 2 deletions src/default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

// Default configuration for a repo in node.js
module.exports = {
sharding: true,
lock: 'fs',
fs: require('datastore-fs'),
level: require('leveldown'),
sharding: true
level: require('leveldown')
}
17 changes: 6 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const debug = require('debug')
const version = require('./version')
const config = require('./config')
const blockstore = require('./blockstore')
const defaultOptions = require('./default-options')

const log = debug('repo')

Expand All @@ -43,21 +44,15 @@ class IpfsRepo {
constructor (repoPath, options) {
assert.equal(typeof repoPath, 'string', 'missing repoPath')

if (options == null) {
options = require('./default-options')
}
this.options = Object.assign({}, defaultOptions, options)

this.closed = true
this.path = repoPath
this.options = Object.assign({
sharding: true,
lock: 'fs'
}, options)
this._fsOptions = Object.assign({}, options.fsOptions)
const FsStore = this.options.fs
this._fsStore = new FsStore(this.path, Object.assign({}, this._fsOptions, {
const fsOptions = Object.assign({}, this.options.fsOptions, {
extension: ''
}))
})
this._fsStore = new FsStore(this.path, fsOptions)

this.version = version(this._fsStore)
this.config = config(this._fsStore)
Expand Down Expand Up @@ -122,7 +117,7 @@ class IpfsRepo {

log('creating flatfs')
const FsStore = this.options.fs
const s = new FsStore(path.join(this.path, flatfsDirectory), this._fsOptions)
const s = new FsStore(path.join(this.path, flatfsDirectory), Object.assign({}, this.options.fsOptions))

if (this.options.sharding) {
const shard = new core.shard.NextToLast(2)
Expand Down

0 comments on commit 42ee0e6

Please sign in to comment.