@@ -4,14 +4,7 @@ import parallelBatch from 'it-parallel-batch'
44import * as rawCodec from 'multiformats/codecs/raw'
55import { CustomProgressEvent } from 'progress-events'
66import { persist } from '../utils/persist.js'
7- import type {
8- BufferImporter ,
9- File ,
10- InProgressImportResult ,
11- WritableStorage ,
12- SingleBlockImportResult ,
13- ImporterProgressEvents
14- } from '../index.js'
7+ import type { BufferImporter , File , InProgressImportResult , WritableStorage , SingleBlockImportResult , ImporterProgressEvents } from '../index.js'
158import type { FileLayout , Reducer } from '../layout/index.js'
169import type { PBLink , PBNode } from '@ipld/dag-pb'
1710import type { CID , Version } from 'multiformats/cid'
@@ -22,18 +15,11 @@ interface BuildFileBatchOptions {
2215 blockWriteConcurrency : number
2316}
2417
25- async function * buildFileBatch (
26- file : File ,
27- blockstore : WritableStorage ,
28- options : BuildFileBatchOptions
29- ) : AsyncGenerator < InProgressImportResult > {
18+ async function * buildFileBatch ( file : File , blockstore : WritableStorage , options : BuildFileBatchOptions ) : AsyncGenerator < InProgressImportResult > {
3019 let count = - 1
3120 let previous : SingleBlockImportResult | undefined
3221
33- for await ( const entry of parallelBatch (
34- options . bufferImporter ( file , blockstore ) ,
35- options . blockWriteConcurrency
36- ) ) {
22+ for await ( const entry of parallelBatch ( options . bufferImporter ( file , blockstore ) , options . blockWriteConcurrency ) ) {
3723 count ++
3824
3925 if ( count === 0 ) {
@@ -78,10 +64,8 @@ export interface LayoutLeafProgress {
7864 path ?: string
7965}
8066
81- export type ReducerProgressEvents = ProgressEvent <
82- 'unixfs:importer:progress:file:layout' ,
83- LayoutLeafProgress
84- >
67+ export type ReducerProgressEvents =
68+ ProgressEvent < 'unixfs:importer:progress:file:layout' , LayoutLeafProgress >
8569
8670interface ReduceOptions extends ProgressOptions < ImporterProgressEvents > {
8771 reduceSingleLeafToSelf : boolean
@@ -93,24 +77,13 @@ function isSingleBlockImport (result: any): result is SingleBlockImportResult {
9377 return result . single === true
9478}
9579
96- const reduce = (
97- file : File ,
98- blockstore : WritableStorage ,
99- options : ReduceOptions
100- ) : Reducer => {
80+ const reduce = ( file : File , blockstore : WritableStorage , options : ReduceOptions ) : Reducer => {
10181 const reducer : Reducer = async function ( leaves ) {
102- if (
103- leaves . length === 1 &&
104- isSingleBlockImport ( leaves [ 0 ] ) &&
105- options . reduceSingleLeafToSelf
106- ) {
82+ if ( leaves . length === 1 && isSingleBlockImport ( leaves [ 0 ] ) && options . reduceSingleLeafToSelf ) {
10783 const leaf = leaves [ 0 ]
10884 let node : Uint8Array | PBNode = leaf . block
10985
110- if (
111- isSingleBlockImport ( leaf ) &&
112- ( file . mtime !== undefined || file . mode !== undefined )
113- ) {
86+ if ( isSingleBlockImport ( leaf ) && ( file . mtime !== undefined || file . mode !== undefined ) ) {
11487 // only one leaf node which is a raw leaf - we have metadata so convert it into a
11588 // UnixFS entry otherwise we'll have nowhere to store the metadata
11689 leaf . unixfs = new UnixFS ( {
@@ -132,13 +105,10 @@ const reduce = (
132105 }
133106
134107 options . onProgress ?.(
135- new CustomProgressEvent < LayoutLeafProgress > (
136- 'unixfs:importer:progress:file:layout' ,
137- {
138- cid : leaf . cid ,
139- path : leaf . originalPath
140- }
141- )
108+ new CustomProgressEvent < LayoutLeafProgress > ( 'unixfs:importer:progress:file:layout' , {
109+ cid : leaf . cid ,
110+ path : leaf . originalPath
111+ } )
142112 )
143113
144114 return {
@@ -163,11 +133,7 @@ const reduce = (
163133 return true
164134 }
165135
166- if (
167- leaf . unixfs != null &&
168- leaf . unixfs . data == null &&
169- leaf . unixfs . fileSize ( ) > 0n
170- ) {
136+ if ( leaf . unixfs != null && leaf . unixfs . data == null && leaf . unixfs . fileSize ( ) > 0n ) {
171137 return true
172138 }
173139
@@ -208,13 +174,10 @@ const reduce = (
208174 const cid = await persist ( block , blockstore , options )
209175
210176 options . onProgress ?.(
211- new CustomProgressEvent < LayoutLeafProgress > (
212- 'unixfs:importer:progress:file:layout' ,
213- {
214- cid,
215- path : file . originalPath
216- }
217- )
177+ new CustomProgressEvent < LayoutLeafProgress > ( 'unixfs:importer:progress:file:layout' , {
178+ cid,
179+ path : file . originalPath
180+ } )
218181 )
219182
220183 return {
@@ -234,24 +197,14 @@ const reduce = (
234197}
235198
236199export interface FileBuilder {
237- (
238- file : File ,
239- blockstore : WritableStorage ,
240- options : FileBuilderOptions
241- ) : Promise < InProgressImportResult >
200+ ( file : File , blockstore : WritableStorage , options : FileBuilderOptions ) : Promise < InProgressImportResult >
242201}
243202
244- export interface FileBuilderOptions
245- extends BuildFileBatchOptions ,
246- ReduceOptions {
203+ export interface FileBuilderOptions extends BuildFileBatchOptions , ReduceOptions {
247204 layout : FileLayout
248205}
249206
250- export const defaultFileBuilder = async (
251- file : File ,
252- block : WritableStorage ,
253- options : FileBuilderOptions
254- ) : Promise < InProgressImportResult > => {
207+ export const defaultFileBuilder : FileBuilder = async ( file : File , block : WritableStorage , options : FileBuilderOptions ) : Promise < InProgressImportResult > => {
255208 return options . layout (
256209 buildFileBatch ( file , block , options ) ,
257210 reduce ( file , block , options )
0 commit comments