File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
packages/ipfs-unixfs-importer/test Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { chai } from 'aegir/chai'
2
+ import { MemoryBlockstore } from 'blockstore-core'
3
+ import { defaultDirBuilder , type DirBuilder } from '../src/dag-builder/dir.js'
4
+ import {
5
+ defaultFileBuilder ,
6
+ type FileBuilder
7
+ } from '../src/dag-builder/file.js'
8
+ import { importer } from '../src/index.js'
9
+
10
+ describe ( 'CustomParamsDagBuilder' , ( ) => {
11
+ it ( 'should build a dag with custom dir builder' , async ( ) => {
12
+ const counter = { dirCounter : 0 , fileCounter : 0 }
13
+ const customDirBuilder : DirBuilder = async ( ...args ) => {
14
+ counter . dirCounter ++
15
+ return defaultDirBuilder ( ...args )
16
+ }
17
+
18
+ const customFileBuilder : FileBuilder = async ( ...args ) => {
19
+ counter . fileCounter ++
20
+ return defaultFileBuilder ( ...args )
21
+ }
22
+
23
+ const blockstore = new MemoryBlockstore ( )
24
+ const files = [ ]
25
+ for await ( const file of importer (
26
+ [
27
+ {
28
+ path : './src/file.txt' ,
29
+ content : new Uint8Array (
30
+ 'hello world' . split ( '' ) . map ( ( char ) => char . charCodeAt ( 0 ) )
31
+ )
32
+ } ,
33
+ {
34
+ path : './src'
35
+ }
36
+ ] ,
37
+ blockstore ,
38
+ {
39
+ dirBuilder : customDirBuilder ,
40
+ fileBuilder : customFileBuilder
41
+ }
42
+ ) ) {
43
+ files . push ( file )
44
+ }
45
+
46
+ chai . expect ( counter . dirCounter ) . to . equal ( 1 )
47
+ } )
48
+ } )
You can’t perform that action at this time.
0 commit comments