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