Skip to content

Commit

Permalink
fix: create CIDv1 for raw blocks even if cidv is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Mar 9, 2022
1 parent 0ffb39b commit 9afb665
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/file/layout/trickle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Layout from "./api.js"
import * as Chunker from "../chunker/api.js"

/**
* @typedef {{
Expand Down Expand Up @@ -60,7 +61,7 @@ export const open = options => ({

/**
* @param {Trickle} state
* @param {Uint8Array[]} leaves
* @param {Chunker.Buffer[]} leaves
* @returns {Layout.WriteResult<Trickle>}
*/
export const write = (state, leaves) => {
Expand Down
2 changes: 1 addition & 1 deletion src/file/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as Layout from "./layout/api.js"
import * as UnixFS from "../lib.js"
import * as Channel from "../writer/channel.js"
import * as Chunker from "./chunker.js"
import { panic, unreachable, defer } from "../writer/util.js"
import { panic, unreachable } from "../writer/util.js"
import * as Queue from "./layout/queue.js"

/**
Expand Down
9 changes: 8 additions & 1 deletion test/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@ export const parseConfig = async input => {
fileEncoder: UnixFS,
hasher: sha256,
fileLayout: input.trickle ? Trickle : Balanced,
createCID: CID.create.bind(CID, /** @type {0|1} */ (input.cidVersion)),
createCID: input.cidVersion === 0 ? createCIDv0 : CID.createV1,
chunkerConfig: input.chunker,
chunker: await parseChunker(input.chunker),
cid: CID.parse(input.cid),
cmd: input.cmd,
}
}

/**
* @param {number} code
* @param {API.MultihashDigest} hash
* @returns
*/
const createCIDv0 = (code, hash) =>
code === UnixFS.code ? CID.createV0(hash) : CID.createV1(code, hash)
/**
* @param {string} input
*/
Expand Down

0 comments on commit 9afb665

Please sign in to comment.