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

Commit 8dad522

Browse files
committed
feat: adjustments to the ipld-dag-pb format
1 parent 9850c4a commit 8dad522

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/object.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
'use strict'
55

66
const expect = require('chai').expect
7-
const DAGNode = require('ipfs-merkle-dag').DAGNode
7+
const dagPB = require('ipld-dag-pb')
8+
const DAGNode = dagPB.DAGNode
89
const bs58 = require('bs58')
910

1011
module.exports = (common) => {
@@ -89,7 +90,7 @@ module.exports = (common) => {
8990

9091
it('of protobuf encoded buffer', (done) => {
9192
const dNode = new DAGNode(new Buffer('Some data'))
92-
const buf = dNode.marshal()
93+
const buf = dagPB.util.serialize(dNode)
9394

9495
ipfs.object.put(buf, { enc: 'protobuf' }, (err, node) => {
9596
expect(err).to.not.exist
@@ -185,8 +186,8 @@ module.exports = (common) => {
185186

186187
ipfs.object.get(node1.multihash(), (err, node2) => {
187188
expect(err).to.not.exist
188-
// because js-ipfs-api can't infer if the returned Data is Buffer
189-
// or String
189+
// because js-ipfs-api can't infer if the
190+
// returned Data is Buffer or String
190191
if (typeof node2.data === 'string') {
191192
node2.data = new Buffer(node2.data)
192193
}
@@ -488,12 +489,13 @@ module.exports = (common) => {
488489
let testNode
489490
let testNodeWithLink
490491
let testLink
491-
before((done) => {
492-
const obj = {
493-
Data: new Buffer('patch test object'),
494-
Links: []
495-
}
496492

493+
const obj = {
494+
Data: new Buffer('patch test object'),
495+
Links: []
496+
}
497+
498+
before((done) => {
497499
ipfs.object.put(obj, (err, node) => {
498500
expect(err).to.not.exist
499501
testNode = node
@@ -502,12 +504,14 @@ module.exports = (common) => {
502504
})
503505

504506
it('.addLink', (done) => {
505-
const dNode1 = testNode.copy()
507+
const dNode1 = new DAGNode(obj.Data, obj.Links)
506508
const dNode2 = new DAGNode(new Buffer('some other node'))
507-
// note: we need to put the linked obj, otherwise IPFS won't timeout
508-
// cause it needs the node to get its size
509+
510+
// note: we need to put the linked obj, otherwise IPFS won't
511+
// timeout. Reason: it needs the node to get its size
509512
ipfs.object.put(dNode2, (err) => {
510513
expect(err).to.not.exist
514+
511515
dNode1.addNodeLink('link-to-node', dNode2)
512516

513517
ipfs.object.patch.addLink(testNode.multihash(), dNode1.links[0], (err, node3) => {
@@ -667,7 +671,7 @@ module.exports = (common) => {
667671
})
668672

669673
it('.addLink', () => {
670-
const dNode1 = testNode.copy()
674+
const dNode1 = dagPB.util.deserialize(dagPB.util.serialize(testNode))
671675
const dNode2 = new DAGNode(new Buffer('some other node'))
672676
// note: we need to put the linked obj, otherwise IPFS won't timeout
673677
// cause it needs the node to get its size

0 commit comments

Comments
 (0)