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

Commit

Permalink
Revert "fix: pass serialized blob to util.cid (#16)"
Browse files Browse the repository at this point in the history
This reverts commit d8f8687.
  • Loading branch information
richardschneider authored Jun 27, 2018
1 parent d8f8687 commit 3b85597
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
11 changes: 5 additions & 6 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const assert = require('assert')
const setImmediate = require('async/setImmediate')
const waterfall = require('async/waterfall')
const multihashing = require('multihashing-async')
Expand Down Expand Up @@ -76,22 +75,22 @@ exports.deserialize = (data, callback) => {
* @param {?CID} cid - CID if call was successful
*/
/**
* Get the CID of the serialized Git node.
* Get the CID of the DAG-Node.
*
* @param {Buffer} blob - Serialized Git node
* @param {Object} dagNode - Internal representation
* @param {Object} [options] - Ignored
* @param {CidCallback} callback - Callback that handles the return value
* @returns {void}
*/
exports.cid = (blob, options, callback) => {
assert(Buffer.isBuffer(blob), 'blob must be a Buffer')
exports.cid = (dagNode, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
options = options || {}
waterfall([
(cb) => multihashing(blob, resolver.defaultHashAlg, cb),
(cb) => exports.serialize(dagNode, cb),
(serialized, cb) => multihashing(serialized, resolver.defaultHashAlg, cb),
(mh, cb) => cb(null, new CID(1, resolver.multicodec, mh))
], callback)
}
2 changes: 1 addition & 1 deletion test/parse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('git object parsing', () => {

let expCid = util.shaToCid(Buffer.from(object[0], 'hex'))

ipldGit.util.cid(object[1], (err, cid) => {
ipldGit.util.cid(node, (err, cid) => {
expect(err).to.not.exist()
expect(cid).to.exist()

Expand Down
6 changes: 2 additions & 4 deletions test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ describe('IPLD format util', () => {
},
message: 'A message\n'
}
let tagNodeSerialized

it('.serialize and .deserialize', (done) => {
ipldGit.util.serialize(tagNode, (err, serialized) => {
expect(err).to.not.exist()
expect(Buffer.isBuffer(serialized)).to.equal(true)
tagNodeSerialized = serialized
ipldGit.util.deserialize(serialized, (err, deserialized) => {
expect(err).to.not.exist()
expect(tagNode).to.eql(deserialized)
Expand All @@ -38,7 +36,7 @@ describe('IPLD format util', () => {
})

it('.cid', (done) => {
ipldGit.util.cid(tagNodeSerialized, (err, cid) => {
ipldGit.util.cid(tagNode, (err, cid) => {
expect(err).to.not.exist()
expect(cid.version).to.equal(1)
expect(cid.codec).to.equal('git-raw')
Expand All @@ -50,7 +48,7 @@ describe('IPLD format util', () => {
})

it('.cid ignores options', (done) => {
ipldGit.util.cid(tagNodeSerialized, { hashAlg: 'unknown' }, (err, cid) => {
ipldGit.util.cid(tagNode, { hashAlg: 'unknown' }, (err, cid) => {
expect(err).to.not.exist()
expect(cid.version).to.equal(1)
expect(cid.codec).to.equal('git-raw')
Expand Down

0 comments on commit 3b85597

Please sign in to comment.