Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Commit

Permalink
fix: make toV0 and toV1 return CID objects
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jan 21, 2017
1 parent 3e0492f commit 32902e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ class CID {
}

toV0 () {
return this.multihash
if (this.codec !== 'dag-pb') {
throw new Error('Cannot convert a non dag-pb CID to CIDv0')
}

return new CID(0, this.codec, this.multihash)
}

toV1 () {
return this.buffer
return new CID(1, this.codec, this.multihash)
}

/* defaults to base58btc */
Expand Down
10 changes: 3 additions & 7 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,11 @@ describe('CID', () => {
it('.equals v0 to v1 and vice versa', () => {
const cidV1Str = 'zdj7Wd8AMwqnhJGQCbFxBVodGSBG84TM7Hs1rcJuQMwTyfEDS'
const cidV1 = new CID(cidV1Str)
const cidV0 = new CID(cidV1.toV0())
const cidV0 = cidV1.toV0()

expect(
cidV0.equals(cidV1)
).to.be.eql(false)
expect(cidV0.equals(cidV1)).to.be.false

expect(
cidV1.equals(cidV0)
).to.be.eql(false)
expect(cidV1.equals(cidV0)).to.be.false

expect(cidV1.multihash).to.eql(cidV0.multihash)
})
Expand Down

0 comments on commit 32902e3

Please sign in to comment.