Skip to content
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

Use dignified.js #30

Merged
merged 3 commits into from
Apr 13, 2016
Merged
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
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.

37 changes: 15 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@
"name": "ipfs-merkle-dag",
"version": "0.3.0",
"description": "A JavaScript implementations of the IPFS MerkleDAG implementations (protobufs)",
"main": "./src/index.js",
"main": "lib/index.js",
"jsnext: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",
"coverage": "dignified-coverage"
},
"pre-commit": [
"lint",
"test"
],
"author": "Vijayee Kulkaa <[email protected]>",
"contributors": [
"David Dias <[email protected]>"
"David Dias <[email protected]>",
"Friedel Ziegelmayer <[email protected]>"
],
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/vijayee/js-ipfs-merkle-dag.git"
},
"dependencies": {
"bs58": "^3.0.0",
"detect-node": "^2.0.3",
"ipfs-blocks": "^0.1.0",
"is-ipfs": "^0.2.0",
"multihashing": "^0.2.0",
Expand All @@ -31,29 +38,15 @@
},
"devDependencies": {
"async": "^1.5.2",
"brfs": "^1.4.3",
"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",
"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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one dependency to save 0 lines of code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one dependency to solve real world issues: ipfs-inactive/js-ipfs-http-client#154

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