@@ -116,55 +116,40 @@ The `@autonomys/auto-dag-data` package provides utilities for creating and manag
116
116
117
117
#### ** Creating an IPLD DAG from a File**
118
118
119
+ To create an IPLD DAG from a file, you can use the ` processFileToIPLDFormat ` function:
120
+
119
121
``` typescript
120
- // Import necessary functions
121
- import { createFileIPLDDag } from ' @autonomys/auto-dag-data '
122
+ import { processFileToIPLDFormat } from ' @autonomys/auto-dag-data '
123
+ import { MemoryBlockstore } from ' blockstore-core/memory '
122
124
import fs from ' fs'
123
125
124
- const fileBuffer = fs .readFileSync (' path/to/your/file.txt' )
125
-
126
- // Create an IPLD DAG from the file data
127
- const dag = createFileIPLDDag (fileBuffer , ' file.txt' )
126
+ const fileStream = fs .createReadStream (' path/to/your/file.txt' )
127
+ const fileSize = fs .statSync (' path/to/your/file.txt' ).size
128
128
129
- console .log (` Created DAG with head CID: ${dag .headCID } ` )
130
-
131
- // The 'nodes' map contains all nodes in the DAG
132
- console .log (` Total nodes in DAG: ${dag .nodes .size } ` )
129
+ const blockstore = new MemoryBlockstore ()
130
+ const fileCID = processFileToIPLDFormat (blockstore , fileStream , totalSize , ' file.txt' )
133
131
```
134
132
135
133
#### ** Creating an IPLD DAG from a Folder**
136
134
135
+ To generate an IPLD DAG from a folder, you can use the ` processFolderToIPLDFormat ` function:
136
+
137
137
``` typescript
138
- // Import necessary functions
139
- import { createFolderIPLDDag } from ' @autonomys/auto-dag-data '
138
+ import { processFolderToIPLDFormat , decodeNode } from ' @autonomys/auto-dag-data '
139
+ import { MemoryBlockstore } from ' blockstore-core/memory '
140
140
import { CID } from ' multiformats'
141
- import fs from ' fs'
142
- import path from ' path'
143
-
144
- // Function to read files from a directory and create CIDs
145
- function getFilesCIDs(directoryPath : string ): CID [] {
146
- const fileNames = fs .readdirSync (directoryPath )
147
- const cids: CID [] = []
148
-
149
- fileNames .forEach ((fileName ) => {
150
- const filePath = path .join (directoryPath , fileName )
151
- const fileBuffer = fs .readFileSync (filePath )
152
- const fileDag = createFileIPLDDag (fileBuffer , fileName )
153
- cids .push (fileDag .headCID )
154
- })
155
-
156
- return cids
157
- }
158
141
159
- const directoryPath = ' path/to/your/folder'
160
- const childCIDs = getFilesCIDs (directoryPath )
142
+ // Example child CIDs and folder information
143
+ const childCIDs: CID [] = [
144
+ /* array of CIDs */
145
+ ]
161
146
const folderName = ' my-folder'
162
- const folderSize = childCIDs . length
147
+ const folderSize = 1024 // size in bytes (the sum of their children size)
163
148
164
- // Create an IPLD DAG for the folder
165
- const folderDag = createFolderIPLDDag ( childCIDs , folderName , folderSize )
149
+ const blockstore = new MemoryBlockstore ()
150
+ const folderCID = processFolderToIPLDFormat ( blockstore , childCIDs , folderName , folderSize )
166
151
167
- console . log ( ` Created folder DAG with head CID: ${ folderDag . headCID } ` )
152
+ const node = decodeNode ( blockstore . get ( folderCID ) )
168
153
```
169
154
170
155
### 3. Using ` @autonomys/auto-id `
0 commit comments