Skip to content

Commit da56594

Browse files
committed
chore: revert formatting changes
1 parent 7f72f3a commit da56594

File tree

4 files changed

+51
-146
lines changed

4 files changed

+51
-146
lines changed

packages/ipfs-unixfs-importer/src/dag-builder/dir.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { encode, prepare } from '@ipld/dag-pb'
22
import { UnixFS } from 'ipfs-unixfs'
33
import { persist } from '../utils/persist.js'
4-
import type {
5-
Directory,
6-
InProgressImportResult,
7-
WritableStorage
8-
} from '../index.js'
4+
import type { Directory, InProgressImportResult, WritableStorage } from '../index.js'
95
import type { Version } from 'multiformats/cid'
106

117
export interface DirBuilderOptions {
@@ -14,18 +10,10 @@ export interface DirBuilderOptions {
1410
}
1511

1612
export interface DirBuilder {
17-
(
18-
dir: Directory,
19-
blockstore: WritableStorage,
20-
options: DirBuilderOptions
21-
): Promise<InProgressImportResult>
13+
(dir: Directory, blockstore: WritableStorage, options: DirBuilderOptions): Promise<InProgressImportResult>
2214
}
2315

24-
export const defaultDirBuilder = async (
25-
dir: Directory,
26-
blockstore: WritableStorage,
27-
options: DirBuilderOptions
28-
): Promise<InProgressImportResult> => {
16+
export const defaultDirBuilder: DirBuilder = async (dir: Directory, blockstore: WritableStorage, options: DirBuilderOptions): Promise<InProgressImportResult> => {
2917
const unixfs = new UnixFS({
3018
type: 'directory',
3119
mtime: dir.mtime,

packages/ipfs-unixfs-importer/src/dag-builder/file.ts

Lines changed: 20 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ import parallelBatch from 'it-parallel-batch'
44
import * as rawCodec from 'multiformats/codecs/raw'
55
import { CustomProgressEvent } from 'progress-events'
66
import { 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'
158
import type { FileLayout, Reducer } from '../layout/index.js'
169
import type { PBLink, PBNode } from '@ipld/dag-pb'
1710
import 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

8670
interface 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

236199
export 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)

packages/ipfs-unixfs-importer/src/dag-builder/index.ts

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@ import type { DirBuilder, DirBuilderOptions } from './dir.js'
66
import type { FileBuilder, FileBuilderOptions } from './file.js'
77
import type { ChunkValidator } from './validate-chunks.js'
88
import type { Chunker } from '../chunker/index.js'
9-
import type {
10-
Directory,
11-
File,
12-
FileCandidate,
13-
ImportCandidate,
14-
ImporterProgressEvents,
15-
InProgressImportResult,
16-
WritableStorage
17-
} from '../index.js'
9+
import type { Directory, File, FileCandidate, ImportCandidate, ImporterProgressEvents, InProgressImportResult, WritableStorage } from '../index.js'
1810
import type { ProgressEvent, ProgressOptions } from 'progress-events'
1911

2012
/**
@@ -37,10 +29,8 @@ export interface ImportReadProgress {
3729
path?: string
3830
}
3931

40-
export type DagBuilderProgressEvents = ProgressEvent<
41-
'unixfs:importer:progress:file:read',
42-
ImportReadProgress
43-
>
32+
export type DagBuilderProgressEvents =
33+
ProgressEvent<'unixfs:importer:progress:file:read', ImportReadProgress>
4434

4535
function isIterable (thing: any): thing is Iterable<any> {
4636
return Symbol.iterator in thing
@@ -50,9 +40,7 @@ function isAsyncIterable (thing: any): thing is AsyncIterable<any> {
5040
return Symbol.asyncIterator in thing
5141
}
5242

53-
function contentAsAsyncIterable (
54-
content: Uint8Array | AsyncIterable<Uint8Array> | Iterable<Uint8Array>
55-
): AsyncIterable<Uint8Array> {
43+
function contentAsAsyncIterable (content: Uint8Array | AsyncIterable<Uint8Array> | Iterable<Uint8Array>): AsyncIterable<Uint8Array> {
5644
try {
5745
if (content instanceof Uint8Array) {
5846
return (async function * () {
@@ -72,10 +60,7 @@ function contentAsAsyncIterable (
7260
throw new InvalidContentError('Content was invalid')
7361
}
7462

75-
export interface DagBuilderOptions
76-
extends FileBuilderOptions,
77-
DirBuilderOptions,
78-
ProgressOptions<ImporterProgressEvents> {
63+
export interface DagBuilderOptions extends FileBuilderOptions, DirBuilderOptions, ProgressOptions<ImporterProgressEvents> {
7964
chunker: Chunker
8065
chunkValidator: ChunkValidator
8166
wrapWithDirectory: boolean
@@ -88,9 +73,7 @@ export type ImporterSourceStream =
8873
| Iterable<ImportCandidate>
8974

9075
export interface DAGBuilder {
91-
(source: ImporterSourceStream, blockstore: WritableStorage): AsyncIterable<
92-
() => Promise<InProgressImportResult>
93-
>
76+
(source: ImporterSourceStream, blockstore: WritableStorage): AsyncIterable<() => Promise<InProgressImportResult>>
9477
}
9578

9679
export function defaultDagBuilder (options: DagBuilderOptions): DAGBuilder {
@@ -102,7 +85,7 @@ export function defaultDagBuilder (options: DagBuilderOptions): DAGBuilder {
10285
originalPath = entry.path
10386
entry.path = entry.path
10487
.split('/')
105-
.filter((path) => path != null && path !== '.')
88+
.filter(path => path != null && path !== '.')
10689
.join('/')
10790
}
10891

@@ -114,22 +97,15 @@ export function defaultDagBuilder (options: DagBuilderOptions): DAGBuilder {
11497
content: (async function * () {
11598
let bytesRead = 0n
11699

117-
for await (const chunk of options.chunker(
118-
options.chunkValidator(contentAsAsyncIterable(entry.content))
119-
)) {
100+
for await (const chunk of options.chunker(options.chunkValidator(contentAsAsyncIterable(entry.content)))) {
120101
const currentChunkSize = BigInt(chunk.byteLength)
121102
bytesRead += currentChunkSize
122103

123-
options.onProgress?.(
124-
new CustomProgressEvent<ImportReadProgress>(
125-
'unixfs:importer:progress:file:read',
126-
{
127-
bytesRead,
128-
chunkSize: currentChunkSize,
129-
path: entry.path
130-
}
131-
)
132-
)
104+
options.onProgress?.(new CustomProgressEvent<ImportReadProgress>('unixfs:importer:progress:file:read', {
105+
bytesRead,
106+
chunkSize: currentChunkSize,
107+
path: entry.path
108+
}))
133109

134110
yield chunk
135111
}
@@ -148,9 +124,7 @@ export function defaultDagBuilder (options: DagBuilderOptions): DAGBuilder {
148124
originalPath
149125
}
150126

151-
const dirBuilder =
152-
options.dirBuilder ??
153-
defaultDirBuilder
127+
const dirBuilder = options.dirBuilder ?? defaultDirBuilder
154128

155129
yield async () => dirBuilder(dir, blockstore, options)
156130
} else {
Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { chai } from 'aegir/chai'
1+
import { expect } from 'aegir/chai'
22
import { MemoryBlockstore } from 'blockstore-core'
33
import { defaultDirBuilder } from '../src/dag-builder/dir.js'
4-
import {
5-
defaultFileBuilder
6-
7-
} from '../src/dag-builder/file.js'
4+
import { defaultFileBuilder } from '../src/dag-builder/file.js'
85
import { importer } from '../src/index.js'
96
import type { DirBuilder } from '../src/dag-builder/dir.js'
107
import type { FileBuilder } from '../src/dag-builder/file.js'
@@ -24,27 +21,20 @@ describe('CustomParamsDagBuilder', () => {
2421

2522
const blockstore = new MemoryBlockstore()
2623
const files = []
27-
for await (const file of importer(
28-
[
29-
{
30-
path: './src/file.txt',
31-
content: new Uint8Array(
32-
'hello world'.split('').map((char) => char.charCodeAt(0))
33-
)
34-
},
35-
{
36-
path: './src'
37-
}
38-
],
39-
blockstore,
40-
{
41-
dirBuilder: customDirBuilder,
42-
fileBuilder: customFileBuilder
43-
}
44-
)) {
24+
for await (const file of importer([{
25+
path: './src/file.txt',
26+
content: new Uint8Array(
27+
'hello world'.split('').map((char) => char.charCodeAt(0))
28+
)
29+
}, {
30+
path: './src'
31+
}], blockstore, {
32+
dirBuilder: customDirBuilder,
33+
fileBuilder: customFileBuilder
34+
})) {
4535
files.push(file)
4636
}
4737

48-
chai.expect(counter.dirCounter).to.equal(1)
38+
expect(counter.dirCounter).to.equal(1)
4939
})
5040
})

0 commit comments

Comments
 (0)