/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@web3-storage/upload-client@17.1.4/dist/src/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import*as PieceHasher from"@web3-storage/data-segment/multihash";import{Storefront}from"@web3-storage/filecoin-client";import*as Link from"multiformats/link";import*as raw from"multiformats/codecs/raw";import{sha256}from"multiformats/hashes/sha2";import*as Store from"./store.js";import*as Blob from"./blob/index.js";import*as BlobAdd from"./blob/add.js";import*as Index from"./index/index.js";import*as IndexAdd from"./index/add.js";import*as Upload from"./upload/index.js";import*as UploadAdd from"./upload/add.js";import*as UnixFS from"./unixfs.js";import*as CAR from"./car.js";import{ShardingStream,defaultFileComparator}from"./sharding.js";import{indexShardedDAG}from"@web3-storage/blob-index";export{Blob,Index,Store,Upload,UnixFS,CAR};export*from"./sharding.js";export{receiptsEndpoint}from"./service.js";export*as Receipt from"./receipts.js";export async function uploadFile(o,r,e={}){return await uploadBlockStream(o,UnixFS.createFileEncoderStream(r,e),e)}export async function uploadDirectory(o,r,e={}){const{customOrder:a=!1}=e,t=a?r:[...r].sort(defaultFileComparator);return await uploadBlockStream(o,UnixFS.createDirectoryEncoderStream(t,e),e)}export async function uploadCAR(o,r,e={}){const a=new CAR.BlockStream(r);return e.rootCID=e.rootCID??(await a.getRoots())[0],await uploadBlockStream(o,a,e)}async function uploadBlockStream(o,r,{pieceHasher:e=PieceHasher,...a}={}){const t="function"==typeof o?o:()=>o,i=[],s=[];let n=null;if(await r.pipeThrough(new ShardingStream(a)).pipeThrough(new TransformStream({async transform(o,r){const i=new Uint8Array(await o.arrayBuffer()),s=await sha256.digest(i),n=await t([{can:BlobAdd.ability,nb:BlobAdd.input(s,i.length)}]);await Blob.add(n,s,i,a);const d=Link.create(CAR.code,s);let c;if(e){const o=await e.digest(i);c=Link.create(raw.code,o);const r=Link.create(raw.code,s),t=await Storefront.filecoinOffer({issuer:n.issuer,audience:n.audience,with:n.issuer.did(),proofs:n.proofs},r,c,a);if(t.out.error)throw new Error("failed to offer piece for aggregation into filecoin deal",{cause:t.out.error})}const{version:l,roots:m,size:p,slices:f}=o;r.enqueue({version:l,roots:m,size:p,cid:d,piece:c,slices:f})}})).pipeTo(new WritableStream({write(o){n=n||o.roots[0],s.push(o.cid),o.slices.set(o.cid.multihash,[0,o.size]),i.push(o.slices),a.onShardStored&&a.onShardStored(o)}})),!n)throw new Error("missing root CID");const d=await indexShardedDAG(n,s,i);if(!d.ok)throw new Error("failed to archive DAG index",{cause:d.error});const c=await sha256.digest(d.ok),l=Link.create(CAR.code,c),[m,p,f]=await Promise.all([t([{can:BlobAdd.ability,nb:BlobAdd.input(c,d.ok.length)}]),t([{can:IndexAdd.ability,nb:IndexAdd.input(l)}]),t([{can:UploadAdd.ability,nb:UploadAdd.input(n,s)}])]);return await Blob.add(m,c,d.ok,a),await Index.add(p,l,a),await Upload.add(f,n,s,a),n}
//# sourceMappingURL=/sm/915ae7cdbff3dda25f4e75a08f27be3ba1374056977a0774122faa7e1b61bbc6.map