Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
ADdress CR feedback. Add missing buffer-loader dep.
Browse files Browse the repository at this point in the history
  • Loading branch information
haadcode committed Nov 16, 2016
1 parent d253d73 commit 0cd8823
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
"stable": "^0.1.5"
},
"devDependencies": {
"aegir": "^9.1.1",
"aegir": "^9.1.2",
"bs58": "^3.0.0",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"chai-checkmark": "^1.0.1",
"fs-pull-blob-store": "^0.4.1",
Expand All @@ -61,7 +62,6 @@
"lodash": "^4.17.0",
"ncp": "^2.0.0",
"pre-commit": "^1.1.3",
"rimraf": "^2.5.4",
"webpack": "2.1.0-beta.25"
"rimraf": "^2.5.4"
}
}
2 changes: 1 addition & 1 deletion src/dag-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DAGLink {
return {
name: this.name,
size: this.size,
hash: this.multihash ? mh.toB58String(this.multihash) : null
hash: this.multihash ? mh.toB58String(this.multihash) : undefined
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const DAGNode = require('./dag-node-utils.js')
const DAGNode = require('./utils.js')
exports.DAGNode = DAGNode
exports.DAGLink = require('./dag-link.js')
exports.resolver = require('./resolver.js')
Expand Down
2 changes: 1 addition & 1 deletion src/resolver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const util = require('./dag-node-utils').util
const util = require('./utils').util
const bs58 = require('bs58')

exports = module.exports
Expand Down
20 changes: 8 additions & 12 deletions src/dag-node-utils.js → src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

const multihashing = require('multihashing-async')
const CID = require('cids')
const stable = require('stable')
const sort = stable.inplace
const sort = require('stable').inplace
const protobuf = require('protocol-buffers')
const proto = protobuf(require('./dag.proto'))
const DAGNode = require('./dag-node')
Expand Down Expand Up @@ -62,7 +61,7 @@ function create (data, dagLinks, hashAlg, callback) {
if (err) {
callback(err)
}
hash(hashAlg, serialized, (err, multihash) => {
multihashing(serialized, hashAlg, (err, multihash) => {
if (err) {
callback(err)
}
Expand All @@ -81,16 +80,13 @@ function addLink (dagNode, nameOrLink, nodeOrMultihash, callback) {
nameOrLink.constructor.name === 'DAGLink')) {
// It's a link
newLink = nameOrLink
} else if (typeof nameOrLink === 'string') {
// It's a name
if ((nodeOrMultihash.constructor &&
nodeOrMultihash.constructor.name === 'DAGNode')) {
// It's a node
// haadcode: not sure what ^ means, so the line below might not be correct
newLink = toDAGLink(nodeOrMultihash)
} else {
// It's a multihash
// haadcode: not sure what ^ means, so the line below might not be correct
newLink = new DAGLink(null, dagNode.size, nodeOrMultihash)
}
}
Expand All @@ -99,22 +95,22 @@ function addLink (dagNode, nameOrLink, nodeOrMultihash, callback) {
links.push(newLink)
sort(links, linkSort)
} else {
throw new Error('Link given as the argument is invalid')
return callback(new Error('Link given as the argument is invalid'), null)
}

create(data, links, callback)
}

function removeLink (dagNode, nameOrMultihash, callback) {
let data = _cloneData(dagNode)
const data = _cloneData(dagNode)
let links = _cloneLinks(dagNode)

if (typeof nameOrMultihash === 'string') {
links = dagNode.links.filter((link) => link.name !== nameOrMultihash)
links = links.filter((link) => link.name !== nameOrMultihash)
} else if (Buffer.isBuffer(nameOrMultihash)) {
links = dagNode.links.filter((link) => !link.hash.equals(nameOrMultihash))
links = links.filter((link) => !link.hash.equals(nameOrMultihash))
} else {
throw new Error('second arg needs to be a name or multihash')
return callback(new Error('second arg needs to be a name or multihash'), null)
}

create(data, links, callback)
Expand Down Expand Up @@ -167,7 +163,7 @@ function toProtoBuf (node) {
if (node.data && node.data.length > 0) {
pbn.Data = node.data
} else {
pbn.Data = null // new Buffer(0)
pbn.Data = null//new Buffer(0)
}

if (node.links.length > 0) {
Expand Down

0 comments on commit 0cd8823

Please sign in to comment.