p2p、分布式,区块链笔记: IPFS库Helia的文件系统Unix File System (UnixFS)

Unix File System (UnixFS)

在这里插入图片描述

importer:导入文件并创建DAG

/**
 * The importer creates UnixFS DAGs and stores the blocks that make
 * them up in the passed blockstore.
 *
 * @example
 *
 * ```typescript
 * import { importer } from 'ipfs-unixfs-importer'
 * import { MemoryBlockstore } from 'blockstore-core'
 *
 * // store blocks in memory, other blockstores are available
 * const blockstore = new MemoryBlockstore()
 *
 * const input = [{
 *   path: './foo.txt',
 *   content: Uint8Array.from([0, 1, 2, 3, 4])
 * }, {
 *   path: './bar.txt',
 *   content: Uint8Array.from([0, 1, 2, 3, 4])
 * }]
 *
 * for await (const entry of importer(input, blockstore)) {
 *   console.info(entry)
 *   // { cid: CID(), ... }
 * }
 * ```
 */
export async function* importer(source, blockstore, options = {}) {
    let candidates;
    if (Symbol.asyncIterator in source || Symbol.iterator in source) {
        candidates = source;
    }
    else {
        candidates = [source];
    }
    const wrapWithDirectory = options.wrapWithDirectory ?? false;
    const shardSplitThresholdBytes = options.shardSplitThresholdBytes ?? 262144;
    const shardFanoutBits = options.shardFanoutBits ?? 8;
    const cidVersion = options.cidVersion ?? 1;
    const rawLeaves = options.rawLeaves ?? true;
    const leafType = options.leafType ?? 'file';
    const fileImportConcurrency = options.fileImportConcurrency ?? 50;
    const blockWriteConcurrency = options.blockWriteConcurrency ?? 10;
    const reduceSingle
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值