Skip to content

Use dignified.js #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ build
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

dist
lib
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ before_install:
- npm i -g npm
# Workaround for a permissions issue with Travis virtual machine images
script:
- npm run lint
- npm test

before_script:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ js-ipfs-repo
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Build Status](https://travis-ci.org/ipfs/js-ipfs-repo.svg)](https://travis-ci.org/ipfs/js-ipfs-repo)
![](https://img.shields.io/badge/coverage-90%25-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/diasdavid/js-peer-id.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-repo)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) [![dignified.js](https://img.shields.io/badge/uses-dignified.js-blue.svg?style=flat-square)](https://github.com/dignifiedquire/dignified.js)

## Description

Expand Down
48 changes: 0 additions & 48 deletions karma.conf.js

This file was deleted.

31 changes: 9 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"description": "IPFS Repo implementation",
"main": "src/index.js",
"scripts": {
"test": "npm run test:node && npm run test:browser",
"test:node": "mocha tests/node-tests.js",
"test:browser": "karma start karma.conf.js",
"coverage": "istanbul cover --print both -- _mocha tests/node-tests.js",
"lint": "standard"
"test": "dignified-test",
"test:node": "dignified-test node",
"test:browser": "dignified-test browser",
"build": "dignified-build",
"coverage": "istanbul cover --print both -- _mocha test/node.js",
"lint": "dignified-lint",
"release": "dignified-release"
},
"repository": {
"type": "git",
Expand All @@ -24,34 +26,19 @@
"homepage": "https://github.com/ipfs/js-ipfs-repo",
"devDependencies": {
"async": "^1.5.2",
"babel-core": "^6.7.2",
"babel-loader": "^6.2.4",
"babel-polyfill": "^6.7.2",
"babel-preset-es2015": "^6.6.0",
"bl": "^1.1.2",
"bs58": "^3.0.0",
"buffer-loader": "^0.0.1",
"chai": "^3.5.0",
"dignified.js": "^1.0.0",
"fs-blob-store": "^5.2.1",
"idb-plus-blob-store": "^1.0.0",
"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.2",
"karma-phantomjs-launcher": "^1.0.0",
"karma-spec-reporter": "0.0.26",
"karma-webpack": "^1.7.0",
"local-storage-blob-store": "0.0.3",
"lodash": "^4.6.1",
"mocha": "^2.4.5",
"ncp": "^2.0.0",
"phantomjs-prebuilt": "^2.1.6",
"pre-commit": "^1.1.2",
"rimraf": "^2.5.2",
"standard": "^6.0.8",
"webpack": "github:diasdavid/webpack#webpack-1"
"rimraf": "^2.5.2"
},
"dependencies": {
"bl": "^1.1.2",
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

const stores = require('./stores')

exports = module.exports = Repo

function Repo (repoPath, options) {
if (!options) { throw new Error('missing options param') }
if (!options.stores) { throw new Error('missing options.stores param') }

// If options.stores is an abstract-blob-store instead of a map, use it for
// all stores.
if (options.stores.prototype && options.stores.prototype.createWriteSteam) {
var store = options.stores
const store = options.stores
options.stores = {
keys: store,
config: store,
Expand Down Expand Up @@ -70,3 +68,5 @@ function Repo (repoPath, options) {
// .logs
// .setUp(repoPath, options.stores.logs, this.locks)
}

exports = module.exports = Repo
4 changes: 2 additions & 2 deletions src/stores/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ exports.setUp = (basePath, blobStore, locks) => {
let result
try {
result = JSON.parse(config.toString())
} catch (err) {
return callback(err)
} catch (error) {
return callback(error)
}
callback(null, result)
}))
Expand Down
16 changes: 8 additions & 8 deletions src/stores/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ const PREFIX_LENGTH = 8

exports = module.exports

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

return path
}

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

Expand All @@ -27,11 +35,3 @@ exports.setUp = (basePath, blobStore, locks) => {
}
}
}

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

return path
}
18 changes: 9 additions & 9 deletions src/stores/locks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ exports.setUp = (basePath, blobStore) => {

return {
lock: function (cb) {
store.exists(lockFile, doesExist)
function createLock () {
store
.createWriteStream(lockFile)
.on('finish', () => {
cb()
})
.end()
}

function doesExist (err, exists) {
if (err) {
Expand All @@ -24,14 +31,7 @@ exports.setUp = (basePath, blobStore) => {
createLock()
}

function createLock () {
store
.createWriteStream(lockFile)
.on('finish', () => {
cb()
})
.end()
}
store.exists(lockFile, doesExist)
},
unlock: (cb) => {
store.remove(lockFile, (err) => {
Expand Down
3 changes: 1 addition & 2 deletions tests/browser-tests.js → test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

'use strict'

require('babel-polyfill')
const async = require('async')
const store = require('idb-plus-blob-store')
const tests = require('./repo-test')
Expand All @@ -22,7 +21,7 @@ idb.deleteDatabase('ipfs/blocks')
// TODO use arrow funtions again when https://github.com/webpack/webpack/issues/1944 is fixed
describe('IPFS Repo Tests on the Browser', function () {
before(function (done) {
var repoData = []
const repoData = []
repoContext.keys().forEach(function (key) {
repoData.push({
key: key.replace('./', ''),
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/repo-test.js → test/repo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const fs = require('fs')
const isNode = !global.window

const fileA = isNode
? fs.readFileSync(process.cwd() + '/tests/test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')
? fs.readFileSync(process.cwd() + '/test/test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')
: require('buffer!./test-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')

module.exports = function (repo) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.