Skip to content

Commit

Permalink
Use dignified.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Apr 8, 2016
1 parent 805aa79 commit fc3cdf2
Show file tree
Hide file tree
Showing 51 changed files with 37 additions and 84 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ atlassian-ide-plugin.xml
com_crashlytics_export_strings.xml
/node_modules
**/*.log
tests/repo-just-for-test*
/tests/blocks
test/repo-just-for-test*
/test/blocks

dist
lib
54 changes: 0 additions & 54 deletions karma.conf.js

This file was deleted.

31 changes: 11 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
"description": "A JavaScript implementations of the IPFS MerkleDAG implementations (protobufs)",
"main": "./src/index.js",
"scripts": {
"test": "npm run test:node && npm run test:browser",
"test:node": "mocha tests/index.js",
"test:browser": "karma start --single-run=true karma.conf.js",
"lint": "standard"
"lint": "dignified-lint",
"build": "dignified-build",
"test": "dignified-test",
"test:node": "dignified-test node",
"test:browser": "dignified-test browser",
"release": "dignified-release"
},
"pre-commit": [
"lint",
"test"
],
"author": "Vijayee Kulkaa <vijayee.kulkaa@hushmail.com>",
"contributors": [
"David Dias <daviddias@ipfs.io>"
"David Dias <daviddias@ipfs.io>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>"
],
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/vijayee/js-ipfs-merkle-dag.git"
},
"dependencies": {
"detect-node": "^2.0.3",
"ipfs-blocks": "^0.1.0",
"is-ipfs": "^0.2.0",
"multihashing": "^0.2.0",
Expand All @@ -31,29 +35,16 @@
},
"devDependencies": {
"async": "^1.5.2",
"brfs": "^1.4.3",
"bs58": "^3.0.0",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"dignified.js": "github:dignifiedquire/dignified.js",
"fs-blob-store": "^5.2.1",
"idb-plus-blob-store": "^1.0.0",
"ipfs-repo": "^0.5.3",
"json-loader": "^0.5.4",
"karma": "^0.13.19",
"karma-chrome-launcher": "^0.2.2",
"karma-cli": "^0.1.2",
"karma-firefox-launcher": "^0.1.7",
"karma-mocha": "^0.2.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.24",
"karma-webpack": "^1.7.0",
"lodash": "^4.6.1",
"mocha": "^2.4.5",
"ncp": "^2.0.0",
"pre-commit": "^1.1.2",
"rimraf": "^2.5.0",
"standard": "^6.0.8",
"transform-loader": "^0.2.3",
"webpack": "^2.0.7-beta"
"rimraf": "^2.5.0"
}
}
2 changes: 2 additions & 0 deletions src/dag-node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

var util = require('./util')
var protobuf = require('protocol-buffers')
var stable = require('stable')
Expand Down
2 changes: 2 additions & 0 deletions src/dag-service-batch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

var Block = require('ipfs-blocks').Block

exports = module.exports = Batch
Expand Down
12 changes: 8 additions & 4 deletions src/dag-service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const DAGNode = require('./dag-node').DAGNode
const Block = require('ipfs-blocks').Block
const isIPFS = require('is-ipfs')
Expand Down Expand Up @@ -70,8 +72,9 @@ function DAGService (blockService) {
nodeStack.push(node)

var keys = []
var link
for (var i = 0; i < node.links.length; i++) {
var link = node.links[i]
link = node.links[i]
keys.push(link.hash)
}
linkStack = linkStack.concat(keys)
Expand All @@ -81,13 +84,14 @@ function DAGService (blockService) {
if (next) {
this.getRecursive(next, callback, linkStack, nodeStack)
} else {
const compare = (hash) => (node) => {
node.multihash().equals(hash)
}
for (var k = 0; k < nodeStack.length; k++) {
var current = nodeStack[k]
for (var j = 0; j < current.links.length; j++) {
link = current.links[j]
var index = nodeStack.findIndex((node) => {
return node.multihash().equals(link.hash)
})
var index = nodeStack.findIndex(compare(link.hash))
if (index !== -1) {
link.node = nodeStack[index]
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

exports.DAGNode = require('./dag-node.js').DAGNode
exports.DAGLink = require('./dag-node.js').DAGLink
exports.DAGService = require('./dag-service.js')
Expand Down
7 changes: 5 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict'

var multihashing = require('multihashing')
var isNode = require('detect-node')

exports = module.exports

// Hash is the global IPFS hash function. uses multihash SHA2_256, 256 bits
exports.hash = (data) => { return multihashing(data, 'sha2-256') }
exports.isBrowser = () => { return !!global.window }
exports.hash = (data) => multihashing(data, 'sha2-256')
exports.isBrowser = () => !isNode
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/index.js → test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const expect = require('chai').expect
const IPFSRepo = require('ipfs-repo')

describe('node test blocks', () => {
const repoExample = process.cwd() + '/tests/example-repo'
const repoTests = process.cwd() + '/tests/repo-just-for-test' + Date.now()
const repoExample = process.cwd() + '/test/example-repo'
const repoTests = process.cwd() + '/test/repo-just-for-test' + Date.now()

before((done) => {
ncp(repoExample, repoTests, (err) => {
Expand Down

0 comments on commit fc3cdf2

Please sign in to comment.