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

Commit

Permalink
Merge pull request #272 from ipfs/object-proto
Browse files Browse the repository at this point in the history
fix: add support for protobuf in object.put
  • Loading branch information
daviddias committed May 13, 2016
2 parents 388264c + 819bb38 commit 0711284
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/api/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,24 @@ module.exports = (send) => {
}
const enc = options.enc || 'json'

send('object/put', enc, null, buf, (err, result) => {
send('object/put', null, {inputenc: enc}, buf, (err, result) => {
if (err) {
return callback(err)
}

if (Buffer.isBuffer(obj)) {
if (!options.enc) {
obj = { Data: obj, Links: [] }
} else {
} else if (options.enc === 'json') {
obj = JSON.parse(obj.toString())
}
}
let node
if (obj.multihash) {
node = obj
} else if (options.enc === 'protobuf') {
node = new DAGNode()
node.unMarshal(obj)
} else {
node = new DAGNode(obj.Data, obj.Links)
}
Expand Down

0 comments on commit 0711284

Please sign in to comment.