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

fix: add support for protobuf in object.put #272

Merged
merged 1 commit into from
May 13, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet! Thank you (we've been passing enc as just enc for ages)

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