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

fix: convert output of multihash.decode to buffer #71

Merged
merged 1 commit into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"buffer": "^5.6.0",
"cids": "^1.0.0",
"multicodec": "^2.0.0",
"multihashing-async": "^2.0.0",
"multihashing-async": "^2.0.1",
"smart-buffer": "^4.1.0",
"strftime": "^0.10.0",
"uint8arrays": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ exports.serialize = (dagNode) => {
*/
exports.deserialize = (data) => {
if (!Buffer.isBuffer(data)) {
data = Buffer.from(data, data.byteOffset, data.byteLength)
data = Buffer.from(data.buffer, data.byteOffset, data.byteLength)
}

const headLen = gitUtil.find(data, 0)
Expand Down
3 changes: 2 additions & 1 deletion src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const multihash = require('multihashing-async').multihash
const CID = require('cids')
const strftime = require('strftime')
const { Buffer } = require('buffer')

exports = module.exports

Expand Down Expand Up @@ -65,5 +66,5 @@ exports.cidToSha = (cid) => {
return null
}

return mh.digest
return Buffer.from(mh.digest.buffer, mh.digest.byteOffset, mh.digest.byteLength)
}
13 changes: 13 additions & 0 deletions test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ describe('IPLD format util', () => {
expect(blob).to.deep.equal(node)
})

it('.serialize from tree', () => {
const node = {
'file.txt': {
hash: new CID('baf4bcfe5cqe5giojiciib5mci7gbb53xcxqot2i'),
mode: '644'
}
}
const blob = ipldGit.util.serialize(node)
const deserialized = ipldGit.util.deserialize(blob)

expect(deserialized).to.deep.equal(node)
})

it('.serialize and .deserialize', () => {
expect(Buffer.isBuffer(tagBlob)).to.be.true()
const deserialized = ipldGit.util.deserialize(tagBlob)
Expand Down