Skip to content

Commit 4a008a1

Browse files
authored
Merge pull request #217 from autonomys/chore-outdated-doc
chore: update outdated doc
2 parents 2384dae + bc4bbb6 commit 4a008a1

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

README.md

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -116,55 +116,40 @@ The `@autonomys/auto-dag-data` package provides utilities for creating and manag
116116

117117
#### **Creating an IPLD DAG from a File**
118118

119+
To create an IPLD DAG from a file, you can use the `processFileToIPLDFormat` function:
120+
119121
```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'
122124
import fs from 'fs'
123125

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
128128

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')
133131
```
134132

135133
#### **Creating an IPLD DAG from a Folder**
136134

135+
To generate an IPLD DAG from a folder, you can use the `processFolderToIPLDFormat` function:
136+
137137
```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'
140140
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-
}
158141

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+
]
161146
const folderName = 'my-folder'
162-
const folderSize = childCIDs.length
147+
const folderSize = 1024 // size in bytes (the sum of their children size)
163148

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)
166151

167-
console.log(`Created folder DAG with head CID: ${folderDag.headCID}`)
152+
const node = decodeNode(blockstore.get(folderCID))
168153
```
169154

170155
### 3. Using `@autonomys/auto-id`

0 commit comments

Comments
 (0)