diff --git a/src/pack/blob.ts b/src/pack/blob.ts index 27b38c3..4b8e96d 100644 --- a/src/pack/blob.ts +++ b/src/pack/blob.ts @@ -8,7 +8,7 @@ import { MemoryBlockStore } from '../blockstore/memory' import { pack } from './index' import type { PackProperties } from './index' -export async function packToBlob ({ input, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory }: PackProperties) { +export async function packToBlob ({ input, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory, shardSplitThreshold }: PackProperties) { const blockstore = userBlockstore ? userBlockstore : new MemoryBlockStore() const { root, out } = await pack({ input, @@ -16,7 +16,8 @@ export async function packToBlob ({ input, blockstore: userBlockstore, hasher, m hasher, maxChunkSize, maxChildrenPerNode, - wrapWithDirectory + wrapWithDirectory, + shardSplitThreshold }) const carParts = await all(out) diff --git a/src/pack/fs.ts b/src/pack/fs.ts index 8c3c1e5..ae4a291 100644 --- a/src/pack/fs.ts +++ b/src/pack/fs.ts @@ -12,7 +12,7 @@ export type PackToFsProperties = PackProperties & { output?: string } -export async function packToFs ({ input, output, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory }: PackToFsProperties) { +export async function packToFs ({ input, output, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory, shardSplitThreshold }: PackToFsProperties) { const blockstore = userBlockstore ? userBlockstore : new FsBlockStore() const location = output || `${os.tmpdir()}/${(parseInt(String(Math.random() * 1e9), 10)).toString() + Date.now()}` const writable = fs.createWriteStream(location) @@ -24,7 +24,8 @@ export async function packToFs ({ input, output, blockstore: userBlockstore, has hasher, maxChunkSize, maxChildrenPerNode, - wrapWithDirectory + wrapWithDirectory, + shardSplitThreshold }) if (!userBlockstore) { diff --git a/src/pack/index.ts b/src/pack/index.ts index d6535d4..ca53b9a 100644 --- a/src/pack/index.ts +++ b/src/pack/index.ts @@ -20,10 +20,11 @@ export type PackProperties = { maxChunkSize?: number, maxChildrenPerNode?: number, wrapWithDirectory?: boolean, - hasher?: MultihashHasher + hasher?: MultihashHasher, + shardSplitThreshold?: number } -export async function pack ({ input, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory }: PackProperties) { +export async function pack ({ input, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory, shardSplitThreshold }: PackProperties) { if (!input || (Array.isArray(input) && !input.length)) { throw new Error('missing input file(s)') } @@ -38,7 +39,8 @@ export async function pack ({ input, blockstore: userBlockstore, hasher, maxChun hasher: hasher || unixfsImporterOptionsDefault.hasher, maxChunkSize: maxChunkSize || unixfsImporterOptionsDefault.maxChunkSize, maxChildrenPerNode: maxChildrenPerNode || unixfsImporterOptionsDefault.maxChildrenPerNode, - wrapWithDirectory: wrapWithDirectory === false ? false : unixfsImporterOptionsDefault.wrapWithDirectory + wrapWithDirectory: wrapWithDirectory === false ? false : unixfsImporterOptionsDefault.wrapWithDirectory, + ...(shardSplitThreshold) && { shardSplitThreshold : shardSplitThreshold } }) )) diff --git a/src/pack/stream.ts b/src/pack/stream.ts index 4ef2bcb..d21d3ad 100644 --- a/src/pack/stream.ts +++ b/src/pack/stream.ts @@ -20,7 +20,7 @@ export type PackToStreamProperties = PackProperties & { } // Node version of toCar with Node Stream Writable -export async function packToStream ({ input, writable, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory }: PackToStreamProperties) { +export async function packToStream ({ input, writable, blockstore: userBlockstore, hasher, maxChunkSize, maxChildrenPerNode, wrapWithDirectory, shardSplitThreshold }: PackToStreamProperties) { if (!input || (Array.isArray(input) && !input.length)) { throw new Error('given input could not be parsed correctly') } @@ -37,7 +37,8 @@ export async function packToStream ({ input, writable, blockstore: userBlockstor hasher: hasher || unixfsImporterOptionsDefault.hasher, maxChunkSize: maxChunkSize || unixfsImporterOptionsDefault.maxChunkSize, maxChildrenPerNode: maxChildrenPerNode || unixfsImporterOptionsDefault.maxChildrenPerNode, - wrapWithDirectory: wrapWithDirectory === false ? false : unixfsImporterOptionsDefault.wrapWithDirectory + wrapWithDirectory: wrapWithDirectory === false ? false : unixfsImporterOptionsDefault.wrapWithDirectory, + ...(shardSplitThreshold) && { shardSplitThreshold : shardSplitThreshold } }) ))