diff --git a/src/pack/index.ts b/src/pack/index.ts index 00c3499..359e4ac 100644 --- a/src/pack/index.ts +++ b/src/pack/index.ts @@ -11,6 +11,7 @@ export type { ImportCandidateStream } import { Blockstore } from '../blockstore' import { MemoryBlockStore } from '../blockstore/memory' import { unixfsImporterOptionsDefault } from './constants' +import { CIDVersion } from "multiformats/types/src/cid"; export interface PackProperties { input: ImportCandidateStream | ImportCandidate, @@ -24,9 +25,10 @@ export interface PackProperties { * Use raw codec for leaf nodes. Default: true. */ rawLeaves?: boolean + cidVersion?: CIDVersion | undefined } -export async function pack ({ input, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory, rawLeaves }: PackProperties) { +export async function pack ({ input, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory, rawLeaves, cidVersion }: PackProperties) { if (!input || (Array.isArray(input) && !input.length)) { throw new Error('missing input file(s)') } @@ -42,7 +44,8 @@ export async function pack ({ input, blockstore: userBlockstore, hasher, maxChun maxChunkSize: maxChunkSize || unixfsImporterOptionsDefault.maxChunkSize, maxChildrenPerNode: maxChildrenPerNode || unixfsImporterOptionsDefault.maxChildrenPerNode, wrapWithDirectory: wrapWithDirectory === false ? false : unixfsImporterOptionsDefault.wrapWithDirectory, - rawLeaves: rawLeaves == null ? unixfsImporterOptionsDefault.rawLeaves : rawLeaves + rawLeaves: rawLeaves == null ? unixfsImporterOptionsDefault.rawLeaves : rawLeaves, + cidVersion: typeof cidVersion === "number" ? cidVersion : unixfsImporterOptionsDefault.cidVersion }) )) diff --git a/src/pack/stream.ts b/src/pack/stream.ts index dd91eb5..d5f9704 100644 --- a/src/pack/stream.ts +++ b/src/pack/stream.ts @@ -21,7 +21,8 @@ export interface PackToStreamProperties extends PackProperties { } // Node version of toCar with Node Stream Writable -export async function packToStream ({ input, writable, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory, rawLeaves, customStreamSink }: PackToStreamProperties) { + +export async function packToStream ({ input, writable, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory, rawLeaves, customStreamSink, cidVersion }: PackToStreamProperties) { if (!input || (Array.isArray(input) && !input.length)) { throw new Error('given input could not be parsed correctly') } @@ -39,7 +40,8 @@ export async function packToStream ({ input, writable, blockstore: userBlockstor maxChunkSize: maxChunkSize || unixfsImporterOptionsDefault.maxChunkSize, maxChildrenPerNode: maxChildrenPerNode || unixfsImporterOptionsDefault.maxChildrenPerNode, wrapWithDirectory: wrapWithDirectory === false ? false : unixfsImporterOptionsDefault.wrapWithDirectory, - rawLeaves: rawLeaves == null ? unixfsImporterOptionsDefault.rawLeaves : rawLeaves + rawLeaves: rawLeaves == null ? unixfsImporterOptionsDefault.rawLeaves : rawLeaves, + cidVersion: typeof cidVersion === "number" ? cidVersion : unixfsImporterOptionsDefault.cidVersion }), customStreamSink ? customStreamSink : (sources: AsyncGenerator) => sources ))