Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: don't break backwards compatibility on the Block API
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Oct 29, 2016
1 parent 2eeea35 commit 3674b8e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core/components/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ module.exports = function block (self) {
block = new Block(block)
}

if (typeof cid === 'function') {
// legacy (without CID)
callback = cid
cid = new CID(block.key('sha2-256'))
}

self._blockService.put({
block: block,
cid: cid
Expand Down Expand Up @@ -47,8 +53,10 @@ module.exports = function block (self) {
}

function cleanCid (cid) {
if (typeof cid === 'string') {
return new CID(cid)
if (cid.constructor.name === 'CID') {
return cid
}
return cid

// CID constructor knows how to do the cleaning :)
return new CID(cid)
}

0 comments on commit 3674b8e

Please sign in to comment.