Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
chore: Create DAGLink list instead of passing existing links through
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Apr 24, 2018
1 parent a5df7c9 commit 723bbe9
Show file tree
Hide file tree
Showing 15 changed files with 400 additions and 317 deletions.
11 changes: 2 additions & 9 deletions src/core/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const exporter = require('ipfs-unixfs-engine').exporter
const promisify = require('promisify-es6')
const CID = require('cids')
const pull = require('pull-stream/pull')
const collect = require('pull-stream/sinks/collect')
const waterfall = require('async/waterfall')
Expand Down Expand Up @@ -39,11 +38,9 @@ module.exports = function mfsRead (ipfs) {
parents: false
}, done),
(result, done) => {
log('traversed to', result)

waterfall([
(next) => pull(
exporter(new CID(result.node.multihash), ipfs._ipld, {
exporter(result.node.multihash, ipfs._ipld, {
offset: options.offset,
length: options.length
}),
Expand All @@ -56,10 +53,6 @@ module.exports = function mfsRead (ipfs) {
(data, next) => next(null, Buffer.concat(data))
], done)
}
], (error, result) => {
log('Read result', error, result)

callback(error, result)
})
], callback)
})
}
4 changes: 0 additions & 4 deletions src/core/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
traverseTo
} = require('./utils')
const waterfall = require('async/waterfall')
const log = require('debug')('mfs:stat')

const defaultOptions = {
hash: false,
Expand All @@ -34,8 +33,6 @@ module.exports = function mfsStat (ipfs) {
waterfall([
(done) => traverseTo(ipfs, path, options, done),
({ node }, done) => {
log('Traversed to', node)

if (options.hash) {
return done(null, {
hash: bs58.encode(node.multihash)
Expand All @@ -47,7 +44,6 @@ module.exports = function mfsStat (ipfs) {
}

const meta = unmarshal(node.data)
log('Node meta', meta)

let size = 0

Expand Down
286 changes: 0 additions & 286 deletions src/core/utils.js

This file was deleted.

53 changes: 53 additions & 0 deletions src/core/utils/add-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict'

const CID = require('cids')
const dagPb = require('ipld-dag-pb')
const {
DAGNode,
DAGLink
} = dagPb
const waterfall = require('async/waterfall')

const addLink = (ipfs, options, callback) => {
options = Object.assign({}, {
parent: undefined,
child: undefined,
name: undefined,
flush: true
}, options)

if (!options.parent) {
return callback(new Error('No parent passed to addLink'))
}

if (!options.child) {
return callback(new Error('No child passed to addLink'))
}

if (!options.name) {
return callback(new Error('No name passed to addLink'))
}

waterfall([
(done) => {
// Remove the old link if necessary
DAGNode.rmLink(options.parent, options.name, done)
},
(parent, done) => {
// Add the new link to the parent
DAGNode.addLink(parent, new DAGLink(options.name, options.child.size, options.child.hash || options.child.multihash), done)
},
(parent, done) => {
if (!options.flush) {
return done()
}

// Persist the new parent DAGNode
ipfs.dag.put(parent, {
cid: new CID(parent.hash || parent.multihash)
}, (error) => done(error, parent))
}
], callback)
}

module.exports = addLink
Loading

0 comments on commit 723bbe9

Please sign in to comment.