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

Commit

Permalink
feat: Update API, use new block-service, block and ipld-dag-pb
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Oct 3, 2016
1 parent e9155df commit edee5fa
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 126 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# IPFS IPLD
# IPLD Resolver

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-ipld-resolver/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-ipld-resolver?branch=master)
[![Travis CI](https://travis-ci.org/ipfs/js-ipld-resolver.svg?branch=master)](https://travis-ci.org/ipfs/js-ipld-resolver)
[![Circle CI](https://circleci.com/gh/ipfs/js-ipld-resolver.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipld-resolver)
[![Dependency Status](https://david-dm.org/ipfs/js-ipld-resolver.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipld-resolver)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![Coverage Status](https://coveralls.io/repos/github/ipfs/js-ipfs-ipld/badge.svg?branch=master)](https://coveralls.io/github/ipfs/js-ipfs-ipld?branch=master)
[![Travis CI](https://travis-ci.org/ipfs/js-ipfs-ipld.svg?branch=master)](https://travis-ci.org/ipfs/js-ipfs-ipld)
[![Circle CI](https://circleci.com/gh/ipfs/js-ipfs-ipld.svg?style=svg)](https://circleci.com/gh/ipfs/js-ipfs-ipld)
[![Dependency Status](https://david-dm.org/ipfs/js-ipfs-ipld.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-ipld) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)

> JavaScript implementation of the IPLDService
> JavaScript implementation of the IPLD Resolver
## Table of Contents

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ipfs-ipld",
"name": "ipld-resolver",
"version": "3.0.0",
"description": "IPLD implementation in JavaScript",
"description": "IPLD Resolver Implementation in JavaScript",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"pre-commit": [
Expand Down Expand Up @@ -34,7 +34,7 @@
"homepage": "https://github.com/ipfs/js-ipfs-ipld#readme",
"license": "MIT",
"devDependencies": {
"aegir": "^8.0.1",
"aegir": "^8.1.2",
"async": "^2.0.1",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
Expand Down Expand Up @@ -64,4 +64,4 @@
"greenkeeperio-bot <support@greenkeeper.io>",
"nicola <me@nicola.io>"
]
}
}
137 changes: 137 additions & 0 deletions src/ipld-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
'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')

module.exports = class IPLDResolver {
constructor (blockService) {
// TODO instead of throwing, just create an in-memory
// block-service, so it is nice for demos
if (!blockService) {
throw new Error('IPLDService requires a BlockService instance')
}

this.bs = blockService
this.resolvers = {}
this.support(dagPB.resolver.multicodec, dagPB.resolver)
}

// Adds support for an IPLD format
// default ones are dag-pb and dag-cbor
support (multicodec, resolver) {
this.resolvers[multicodec] = resolver
}

resolve (cid, path) {
// TODO
}

put (node, callback) {
callback = callback || noop
pull(
pull.values([node]),
this.putStream(callback)
)
}

putStream (callback) {
callback = callback || noop

return pull(
pull.map((node) => {
return {
block: new Block(node.serialize()),
cid: node.cid()
}
}),
this.bs.putStream(),
pull.onEnd(callback)
)
}

get (cid, callback) {
pull(
this.getStream(cid),
pull.collect((err, res) => {
if (err) {
return callback(err)
}
callback(null, res[0])
})
)
}

getStream (cid) {
return pull(
this.bs.getStream(cid),
pull.map((block) => {
// TODO
// deserialize this block into the format described by the CID
// if the multicodec is not known (i.e we don't have a deserializer)
// send back the raw data

// old -> ipld.unmarshal(block.data)
})
)
}

getRecursive (cid, callback) {
pull(
this.getRecursiveStream(cid),
pull.collect(callback)
)
}

getRecursiveStream (cid) {
return pull(
this.getStream(cid),
pull.map((node) => {
traverse.widthFirst(node, (node) => {
return pull(
pull.values(utils.getKeys(node)),
pull.map((link) => this.getStream(link)),
pull.flatten()
)
})
}),
pull.flatten()
)
}

remove (cids, callback) {
this.bs.delete(cids, callback)
}
}

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
}
*/
115 changes: 0 additions & 115 deletions src/ipld-service.js

This file was deleted.

4 changes: 3 additions & 1 deletion test/ipld-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ module.exports = (repo) => {

it('putStream', (done) => {
pull(
pull.values([{name: 'pull.txt', size: 12}]),
pull.values([
{name: 'pull.txt', size: 12}
]),
ipldService.putStream(done)
)
})
Expand Down

0 comments on commit edee5fa

Please sign in to comment.