Skip to content

Commit

Permalink
fix: Upgrade dependencies, use strict and fix /blocks pathing
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Mar 16, 2016
1 parent 45fcfcc commit a2021b0
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 70 deletions.
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,36 @@
"homepage": "https:/ipfs/js-ipfs-repo",
"devDependencies": {
"async": "^1.5.2",
"bl": "^1.0.0",
"bl": "^1.1.2",
"bs58": "^3.0.0",
"buffer-loader": "^0.0.1",
"chai": "^3.4.1",
"chai": "^3.5.0",
"fs-blob-store": "^5.2.1",
"idb-plus-blob-store": "^1.0.0",
"istanbul": "^0.4.1",
"karma": "^0.13.19",
"istanbul": "^0.4.2",
"karma": "^0.13.22",
"karma-chrome-launcher": "^0.2.2",
"karma-cli": "^0.1.2",
"karma-firefox-launcher": "^0.1.7",
"karma-mocha": "^0.2.1",
"karma-spec-reporter": "0.0.23",
"karma-mocha": "^0.2.2",
"karma-spec-reporter": "0.0.24",
"karma-webpack": "^1.7.0",
"local-storage-blob-store": "0.0.2",
"lodash": "^4.0.0",
"mocha": "^2.3.4",
"local-storage-blob-store": "0.0.3",
"lodash": "^4.6.1",
"mocha": "^2.4.5",
"ncp": "^2.0.0",
"pre-commit": "^1.1.1",
"rimraf": "^2.4.4",
"standard": "^5.1.1",
"pre-commit": "^1.1.2",
"rimraf": "^2.5.2",
"standard": "^6.0.8",
"webpack": "github:diasdavid/webpack#webpack-1"
},
"dependencies": {
"bl": "^1.0.0",
"bl": "^1.1.2",
"concat-stream": "^1.5.1",
"level-js": "^2.2.2",
"level-js": "^2.2.3",
"lockfile": "^1.0.1",
"multihashes": "^0.2.0",
"xtend": "^4.0.1"
}
},
"license": "MIT"
}
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const stores = require('./stores')

exports = module.exports = Repo
Expand All @@ -13,7 +15,7 @@ function Repo (repoPath, options) {
.locks
.setUp(repoPath, options.stores.locks)

this.exists = callback => {
this.exists = (callback) => {
this.version.get((err, version) => {
if (err) {
return callback(new Error('Repo does not exist'))
Expand Down
12 changes: 7 additions & 5 deletions src/stores/config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
var bl = require('bl')
'use strict'

const bl = require('bl')

exports = module.exports

exports.setUp = (basePath, blobStore, locks) => {
var store = blobStore(basePath)
const store = blobStore(basePath)
return {
get: callback => {
get: (callback) => {
store
.createReadStream('config')
.pipe(bl((err, config) => {
if (err) {
return callback(err)
}
var result
let result
try {
result = JSON.parse(config.toString())
} catch (err) {
Expand All @@ -23,7 +25,7 @@ exports.setUp = (basePath, blobStore, locks) => {
},

set: (config, callback) => {
locks.lock(err => {
locks.lock((err) => {
if (err) {
return callback(err)
}
Expand Down
14 changes: 8 additions & 6 deletions src/stores/datastore-legacy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict'

// TODO: This may end up being configurable
// TODO: This should belong to the `fs` implementation

var PREFIX_LENGTH = 8
var multihash = require('multihashes')
var path = require('path')
const PREFIX_LENGTH = 8
const multihash = require('multihashes')
const path = require('path')

module.exports = store => {
module.exports = (store) => {
function hashToPath (hash) {
var folder = hash.slice(0, PREFIX_LENGTH)
const folder = hash.slice(0, PREFIX_LENGTH)
return path.join(folder, hash) + '.data'
}

Expand All @@ -17,7 +19,7 @@ module.exports = store => {
},

write: (buf, cb) => {
var mh = multihash.encode(buf, 'hex')
const mh = multihash.encode(buf, 'hex')
return store.write(hashToPath(mh), buf, cb)
}
}
Expand Down
20 changes: 11 additions & 9 deletions src/stores/datastore.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
'use strict'

const PREFIX_LENGTH = 8

exports = module.exports

exports.setUp = (basePath, blobStore, locks) => {
var store = blobStore(basePath + '/blocks')
const store = blobStore(basePath + '/blocks')

return {
createReadStream: multihash => {
var path = multihashToPath(multihash)
createReadStream: (multihash) => {
const path = multihashToPath(multihash)
return store.createReadStream(path)
},

createWriteStream: (multihash, cb) => {
var path = multihashToPath(multihash)
const path = multihashToPath(multihash)
return store.createWriteStream(path, cb)
},
exists: (multihash, cb) => {
var path = multihashToPath(multihash)
const path = multihashToPath(multihash)
return store.exists(path, cb)
},
remove: (multihash, cb) => {
var path = multihashToPath(multihash)
const path = multihashToPath(multihash)
return store.remove(path, cb)
}
}
}

function multihashToPath (multihash) {
var filename = multihash.toString('hex') + '.data'
var folder = filename.slice(0, PREFIX_LENGTH)
var path = folder + '/' + filename
const filename = multihash.toString('hex') + '.data'
const folder = filename.slice(0, PREFIX_LENGTH)
const path = folder + '/' + filename

return path
}
3 changes: 2 additions & 1 deletion src/stores/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

exports = module.exports

exports.locks = require('./locks')
Expand All @@ -7,4 +9,3 @@ exports.keys = require('./keys')
exports.datastore = require('./datastore')
// exports.datastoreLegacy = require('./datastore-legacy')
// exports.logs = require('./logs')

4 changes: 3 additions & 1 deletion src/stores/keys.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'

exports = module.exports

exports.setUp = (basePath, blobStore, locks, config) => {
return {
get: callback => {
get: (callback) => {
config.get((err, config) => {
if (err) {
return callback(err)
Expand Down
10 changes: 6 additions & 4 deletions src/stores/locks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'

exports = module.exports

exports.setUp = (basePath, blobStore) => {
var store = blobStore(basePath)
var lockFile = 'repo.lock'
const store = blobStore(basePath)
const lockFile = 'repo.lock'

return {
lock: function (cb) {
Expand Down Expand Up @@ -31,8 +33,8 @@ exports.setUp = (basePath, blobStore) => {
.end()
}
},
unlock: cb => {
store.remove(lockFile, err => {
unlock: (cb) => {
store.remove(lockFile, (err) => {
if (err) { return cb(err) }
store.exists(lockFile, (err, exists) => {
if (err) { return cb(err) }
Expand Down
10 changes: 6 additions & 4 deletions src/stores/version.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
var bl = require('bl')
'use strict'

const bl = require('bl')

exports = module.exports

exports.setUp = (basePath, blobStore, locks) => {
var store = blobStore(basePath)
const store = blobStore(basePath)

return {
get: callback => {
get: (callback) => {
store
.createReadStream('version')
.pipe(bl((err, version) => {
Expand All @@ -17,7 +19,7 @@ exports.setUp = (basePath, blobStore, locks) => {
}))
},
set: (value, callback) => {
locks.lock(err => {
locks.lock((err) => {
if (err) {
return callback(err)
}
Expand Down
4 changes: 3 additions & 1 deletion tests/browser-tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* globals describe, before */
/* eslint-env mocha */

'use strict'

const async = require('async')
const store = require('idb-plus-blob-store')
Expand Down
15 changes: 9 additions & 6 deletions tests/node-tests.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
/* globals describe, before, after */
/* eslint-env mocha */

'use strict'

const expect = require('chai').expect
const ncp = require('ncp').ncp
const rimraf = require('rimraf')
const path = require('path')

const IPFSRepo = require('../src')

describe('IPFS Repo Testson on Node.js', () => {
const testRepoPath = __dirname + '/test-repo'
const testRepoPath = path.join(__dirname, 'test-repo')
const date = Date.now().toString()
const repoPath = testRepoPath + date

before(done => {
ncp(testRepoPath, repoPath, err => {
before((done) => {
ncp(testRepoPath, repoPath, (err) => {
expect(err).to.not.exist
done()
})
})

after(done => {
rimraf(repoPath, err => {
after((done) => {
rimraf(repoPath, (err) => {
expect(err).to.not.exist
done()
})
Expand Down
36 changes: 19 additions & 17 deletions tests/repo-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* globals describe, it*/
/* eslint-env mocha */

'use strict'

const expect = require('chai').expect
const base58 = require('bs58')
Expand All @@ -13,7 +15,7 @@ const fileA = isNode

module.exports = function (repo) {
describe('IPFS Repo Tests', function () {
it('check if Repo exists', done => {
it('check if Repo exists', (done) => {
repo.exists((err, exists) => {
expect(err).to.not.exist
expect(exists).to.equal(true)
Expand All @@ -22,29 +24,29 @@ module.exports = function (repo) {
})

describe('locks', () => {
it('lock, unlock', done => {
repo.locks.lock(err => {
it('lock, unlock', (done) => {
repo.locks.lock((err) => {
expect(err).to.not.exist
repo.locks.unlock(err => {
repo.locks.unlock((err) => {
expect(err).to.not.exist
done()
})
})
})

it('lock, lock', done => {
repo.locks.lock(err => {
it('lock, lock', (done) => {
repo.locks.lock((err) => {
expect(err).to.not.exist
repo.locks.lock(err => {
repo.locks.lock((err) => {
expect(err).to.not.exist
repo.locks.unlock(err => {
repo.locks.unlock((err) => {
expect(err).to.not.exist
done()
})
})

setTimeout(() => {
repo.locks.unlock(err => {
repo.locks.unlock((err) => {
expect(err).to.not.exist
})
}, 500)
Expand All @@ -53,7 +55,7 @@ module.exports = function (repo) {
})

describe('keys', () => {
it('get PrivKey', done => {
it('get PrivKey', (done) => {
repo.keys.get((err, privKey) => {
expect(err).to.not.exist
expect(privKey).to.be.a('string')
Expand All @@ -63,16 +65,16 @@ module.exports = function (repo) {
})

describe('config', () => {
it('get config', done => {
it('get config', (done) => {
repo.config.get((err, config) => {
expect(err).to.not.exist
expect(config).to.be.a('object')
done()
})
})

it('set config', done => {
repo.config.set({a: 'b'}, err => {
it('set config', (done) => {
repo.config.set({a: 'b'}, (err) => {
expect(err).to.not.exist
repo.config.get((err, config) => {
expect(err).to.not.exist
Expand All @@ -84,7 +86,7 @@ module.exports = function (repo) {
})

describe('version', () => {
it('get version', done => {
it('get version', (done) => {
repo.version.get((err, version) => {
expect(err).to.not.exist
expect(version).to.be.a('string')
Expand All @@ -93,8 +95,8 @@ module.exports = function (repo) {
})
})

it('set version', done => {
repo.version.set('9000', err => {
it('set version', (done) => {
repo.version.set('9000', (err) => {
expect(err).to.not.exist
repo.version.get((err, version) => {
expect(err).to.not.exist
Expand Down

0 comments on commit a2021b0

Please sign in to comment.