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

Commit

Permalink
feat: create a resolver in memory when no block-service is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Oct 16, 2016
1 parent 436f44c commit 00d5d46
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 454 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
},
"dependencies": {
"babel-runtime": "^6.11.6",
"interface-pull-blob-store": "^0.5.0",
"ipfs-block": "^0.3.0",
"ipld": "^0.6.0",
"is-ipfs": "^0.2.0",
Expand Down
50 changes: 18 additions & 32 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
'use strict'

// const isIPFS = require('is-ipfs')
const Block = require('ipfs-block')
// const ipld = require('ipld-dag-cbor')
const pull = require('pull-stream')
const traverse = require('pull-traverse')
// const mh = require('multihashes')
const dagPB = require('ipld-dag-pb')

const utils = require('./utils')
const IPFSRepo = require('ipfs-repo')
const MemoryStore = require('../node_modules/interface-pull-blob-store/lib/reference.js')
const BlockService = require('ipfs-block-service')

module.exports = class IPLDResolver {
const dagPB = require('ipld-dag-pb')
// const dagCBOR = require('ipld-dag-cbor')
// const isIPFS = require('is-ipfs')
// const mh = require('multihashes')

class IPLDResolver {
constructor (blockService) {
// TODO instead of throwing, just create an in-memory
// block-service, so it is nice for demos
// nicola will love this!
if (!blockService) {
throw new Error('IPLDService requires a BlockService instance')
const repo = new IPFSRepo('in-memory', { stores: MemoryStore })
blockService = new BlockService(repo)
}

this.bs = blockService
this.resolvers = {}

// Support by default dag-pb and dag-cbor
this.support(dagPB.resolver.multicodec, dagPB.DAGNode, dagPB.resolver)
// this.support(dagCBOR.resolver.multicodec, dagCBOR.DAGNode, dagCBOR.resolver)
}

// Adds support for an IPLD format
Expand All @@ -36,6 +42,8 @@ module.exports = class IPLDResolver {
// TODO
}

// Node operations (get and retrieve nodes, not values)

put (node, callback) {
callback = callback || noop
pull(
Expand Down Expand Up @@ -118,26 +126,4 @@ module.exports = class IPLDResolver {

function noop () {}

/*
function normalizeKey (key) {
let res
const isMhash = isIPFS.multihash(key)
const isPath = isIPFS.path(key)
if (!isMhash && !isPath) {
return null
}
if (isMhash) {
res = key
} else if (isPath) {
res = key.replace('/ipfs/', '')
}
if (typeof res === 'string') {
return mh.fromB58String(res)
}
return res
}
*/
module.exports = IPLDResolver
81 changes: 0 additions & 81 deletions src/old-resolve.js

This file was deleted.

5 changes: 1 addition & 4 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ describe('Node.js', () => {
})

after((done) => {
rimraf(repoTests, (err) => {
expect(err).to.equal(null)
done()
})
rimraf(repoTests, done)
})

const repo = new IPFSRepo(repoTests, {stores: Store})
Expand Down
Loading

0 comments on commit 00d5d46

Please sign in to comment.