Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat: merge of get and resolve (#761)
Browse files Browse the repository at this point in the history
* feat: merge of get and resolve
* chore: ^ to ~
  • Loading branch information
daviddias authored Feb 9, 2017
1 parent c73ac5e commit b081e35
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 98 deletions.
48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"homepage": "https://github.com/ipfs/js-ipfs#readme",
"devDependencies": {
"aegir": "^9.4.0",
"aegir": "^10.0.0",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"delay": "^1.3.1",
Expand All @@ -71,10 +71,10 @@
"execa": "^0.6.0",
"expose-loader": "^0.7.1",
"form-data": "^2.1.2",
"fs-pull-blob-store": "^0.4.1",
"fs-pull-blob-store": "~0.4.1",
"gulp": "^3.9.1",
"interface-ipfs-core": "^0.24.0",
"ipfsd-ctl": "^0.18.2",
"interface-ipfs-core": "~0.24.1",
"ipfsd-ctl": "~0.18.3",
"left-pad": "^1.1.3",
"lodash": "^4.17.4",
"mocha": "^3.2.0",
Expand All @@ -91,26 +91,26 @@
"bl": "^1.2.0",
"boom": "^4.2.0",
"debug": "^2.6.0",
"fs-pull-blob-store": "^0.3.0",
"fs-pull-blob-store": "~0.3.0",
"glob": "^7.1.1",
"hapi": "^16.1.0",
"hapi-set-header": "^1.0.2",
"hoek": "^4.1.0",
"idb-pull-blob-store": "^0.5.1",
"ipfs-api": "^12.1.6",
"ipfs-bitswap": "^0.9.2",
"ipfs-block": "^0.5.4",
"ipfs-block-service": "^0.8.1",
"ipfs-multipart": "^0.1.0",
"ipfs-repo": "^0.11.2",
"ipfs-unixfs": "^0.1.9",
"ipfs-unixfs-engine": "^0.16.1",
"ipld-resolver": "^0.6.0",
"idb-pull-blob-store": "~0.5.1",
"ipfs-api": "^12.1.7",
"ipfs-bitswap": "~0.9.3",
"ipfs-block": "~0.5.5",
"ipfs-block-service": "~0.8.3",
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.11.3",
"ipfs-unixfs": "~0.1.10",
"ipfs-unixfs-engine": "~0.17.0",
"ipld-resolver": "~0.8.1",
"isstream": "^0.1.2",
"joi": "^10.2.1",
"libp2p-floodsub": "0.7.2",
"libp2p-ipfs-browser": "^0.17.8",
"libp2p-ipfs-nodejs": "^0.17.9",
"joi": "^10.2.2",
"libp2p-floodsub": "~0.7.3",
"libp2p-ipfs-browser": "~0.17.9",
"libp2p-ipfs-nodejs": "~0.17.10",
"lodash.flatmap": "^4.5.0",
"lodash.get": "^4.4.2",
"lodash.has": "^4.5.2",
Expand All @@ -119,12 +119,12 @@
"lodash.values": "^4.3.0",
"mafmt": "^2.1.6",
"mkdirp": "^0.5.1",
"multiaddr": "^2.2.0",
"multihashes": "^0.3.2",
"multiaddr": "^2.2.1",
"multihashes": "~0.3.3",
"path-exists": "^3.0.0",
"peer-book": "^0.3.0",
"peer-id": "^0.8.1",
"peer-info": "^0.8.2",
"peer-book": "~0.3.1",
"peer-id": "~0.8.2",
"peer-info": "~0.8.3",
"promisify-es6": "^1.0.2",
"pull-file": "^1.0.0",
"pull-paramap": "^1.2.1",
Expand Down
19 changes: 6 additions & 13 deletions src/cli/commands/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,20 @@ module.exports = {

const refParts = argv.ref.split('/')
const cidString = refParts[0]
const pathString = refParts.slice(1).join('/')
const path = refParts.slice(1).join('/')
const cid = new CID(cidString)

let lookupFn
if (pathString) {
lookupFn = () => ipfs.dag.resolve(cid, pathString)
} else {
lookupFn = () => ipfs.dag.get(cid)
}

lookupFn()
.then((obj) => {
ipfs.dag.get(cid, path, (err, result) => {
if (err) {
throw err
}
const obj = result.value
if (Buffer.isBuffer(obj)) {
console.log('0x' + obj.toString('hex'))
} else {
console.log(obj)
}
})
.catch((err) => {
console.error(err)
})
})
}
}
29 changes: 4 additions & 25 deletions src/core/components/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,13 @@

const promisify = require('promisify-es6')

const dagPB = require('ipld-dag-pb')
const dagCBOR = require('ipld-dag-cbor')

module.exports = function dag (self) {
return {
put: promisify((dagNode, multicodec, hashAlg, callback) => {
switch (multicodec) {
case 'dag-pb': dagPB.util.cid(dagNode, gotCid); break
case 'dag-cbor': dagCBOR.util.cid(dagNode, gotCid); break
default: callback(new Error('IPLD Format not supported'))
}

function gotCid (err, cid) {
if (err) {
return callback(err)
}

self._ipldResolver.put({
node: dagNode,
cid: cid
}, callback)
}
}),
get: promisify((cid, callback) => {
self._ipldResolver.get(cid, callback)
put: promisify((dagNode, options, callback) => {
self._ipldResolver.put(dagNode, options, callback)
}),
resolve: promisify((cid, path, callback) => {
self._ipldResolver.resolve(cid, path, callback)
get: promisify((cid, path, options, callback) => {
self._ipldResolver.get(cid, path, options, callback)
})
}
}
10 changes: 6 additions & 4 deletions src/core/components/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,17 @@ module.exports = function files (self) {
return callback(new Error('You must supply a multihash'))
}

self._ipldResolver.get(new CID(hash), (err, node) => {
self._ipldResolver.get(new CID(hash), (err, result) => {
if (err) {
return callback(err)
}

const node = result.value

const data = UnixFS.unmarshal(node.data)

if (data.type === 'directory') {
return callback(
new Error('This dag node is a directory')
)
return callback(new Error('This dag node is a directory'))
}

pull(
Expand Down Expand Up @@ -107,6 +108,7 @@ module.exports = function files (self) {

function prepareFile (self, file, callback) {
const bs58mh = multihashes.toB58String(file.multihash)

waterfall([
(cb) => self.object.get(file.multihash, cb),
(node, cb) => {
Expand Down
20 changes: 13 additions & 7 deletions src/core/components/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ module.exports = function object (self) {
if (err) {
return cb(err)
}
self._ipldResolver.put({
node: node,
self._ipldResolver.put(node, {
cid: new CID(node.multihash)
}, (err) => {
cb(err, node)
Expand Down Expand Up @@ -112,8 +111,7 @@ module.exports = function object (self) {
if (err) {
return callback(err)
}
self._ipldResolver.put({
node: node,
self._ipldResolver.put(node, {
cid: new CID(node.multihash)
}, (err) => {
if (err) {
Expand Down Expand Up @@ -169,8 +167,7 @@ module.exports = function object (self) {
}

function next () {
self._ipldResolver.put({
node: node,
self._ipldResolver.put(node, {
cid: new CID(node.multihash)
}, (err) => {
if (err) {
Expand All @@ -196,7 +193,16 @@ module.exports = function object (self) {
return callback(err)
}
const cid = new CID(mh)
self._ipldResolver.get(cid, callback)

self._ipldResolver.get(cid, (err, result) => {
if (err) {
return callback(err)
}

const node = result.value

callback(null, node)
})
}),

data: promisify((multihash, options, callback) => {
Expand Down
20 changes: 0 additions & 20 deletions test/core/interface/dag-resolve.js

This file was deleted.

1 change: 0 additions & 1 deletion test/core/interface/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('interface-ipfs-core tests', () => {
require('./generic')
require('./object')
require('./dag')
require('./dag-resolve')
if (isNode) {
require('./swarm')
require('./pubsub')
Expand Down
9 changes: 5 additions & 4 deletions test/utils/create-repo-browser.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* global self */
'use strict'

const IPFSRepo = require('ipfs-repo')
const Store = require('idb-pull-blob-store')

const idb = window.indexedDB ||
window.mozIndexedDB ||
window.webkitIndexedDB ||
window.msIndexedDB
const idb = self.indexedDB ||
self.mozIndexedDB ||
self.webkitIndexedDB ||
self.msIndexedDB

function createTempRepo (repoPath) {
repoPath = repoPath || '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8)
Expand Down

0 comments on commit b081e35

Please sign in to comment.