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 #273 from ipfs/fix/object-data
Browse files Browse the repository at this point in the history
Fixing small issues with the new object api
  • Loading branch information
daviddias committed May 16, 2016
2 parents 0a33a61 + a73902b commit 0e382b1
Showing 1 changed file with 56 additions and 9 deletions.
65 changes: 56 additions & 9 deletions src/api/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/get', multihash, null, null, (err, result) => {
if (err) {
Expand Down Expand Up @@ -105,14 +110,23 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/data', multihash, null, null, (err, result) => {
if (err) {
return callback(err)
}

result.pipe(bl(callback))
if (typeof result.pipe === 'function') {
result.pipe(bl(callback))
} else {
callback(null, result)
}
})
}),
links: promisify((multihash, options, callback) => {
Expand All @@ -123,7 +137,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/links', multihash, null, null, (err, result) => {
if (err) {
Expand All @@ -148,7 +167,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/stat', multihash, null, null, callback)
}),
Expand All @@ -175,7 +199,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/patch/add-link', [multihash, dLink.name, bs58.encode(dLink.hash).toString()], null, null, (err, result) => {
if (err) {
Expand All @@ -192,7 +221,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/patch/rm-link', [multihash, dLink.name], null, null, (err, result) => {
if (err) {
Expand All @@ -209,7 +243,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/patch/set-data', [multihash], null, data, (err, result) => {
if (err) {
Expand All @@ -226,7 +265,12 @@ module.exports = (send) => {
if (!options) {
options = {}
}
multihash = cleanMultihash(multihash, options)

try {
multihash = cleanMultihash(multihash, options)
} catch (err) {
return callback(err)
}

send('object/patch/append-data', [multihash], null, data, (err, result) => {
if (err) {
Expand Down Expand Up @@ -262,6 +306,9 @@ function cleanMultihash (multihash, options) {
} else {
throw new Error('not valid multihash')
}
} else if (!multihash) {
throw new Error('missing valid multihash')
}

return multihash
}

0 comments on commit 0e382b1

Please sign in to comment.