@autonomys/auto-drive 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -0
- package/README.md +146 -1
- package/dist/metadata/offchain/file.d.ts.map +1 -1
- package/dist/metadata/offchain/file.js +3 -4
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Autonomys Network (autonomys.xyz)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
1. **Attribution**: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
2. **No Warranty**: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
15
|
+
|
|
16
|
+
3. **Limitation of Liability**: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
+
|
|
18
|
+
---
|
package/README.md
CHANGED
|
@@ -1 +1,146 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Auto-Drive
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
[](https://github.com/autonomys/auto-sdk/tags)
|
|
6
|
+
[](https://github.com/autonomys/auto-sdk/actions/workflows/build.yaml)
|
|
7
|
+
[](https://badge.fury.io/js/@autonomys/auto-drive)
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
The **Autonomys Auto Drive SDK** (`@autonomys/auto-drive`) provides utilities for creating and managing IPLD DAGs (InterPlanetary Linked Data Directed Acyclic Graphs) for files and folders. It facilitates chunking large files, handling metadata, and creating folder structures suitable for distributed storage systems like IPFS.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **File Chunking and DAG Creation**: Efficiently split large files into smaller chunks and create IPLD DAGs.
|
|
16
|
+
- **Folder Structure Creation**: Generate IPLD DAGs for directory structures.
|
|
17
|
+
- **Metadata Handling**: Add and manage metadata for files and folders.
|
|
18
|
+
- **CID Management**: Utilities for working with Content Identifiers (CIDs).
|
|
19
|
+
- **TypeScript Support**: Fully typed for enhanced developer experience.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
You can install Auto-Drive using npm or yarn:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @autonomys/auto-drive
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add @autonomys/auto-drive
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
### Creating an IPLD DAG from a File
|
|
38
|
+
|
|
39
|
+
To create an IPLD DAG from a file, you can use the `createFileIPLDDag` function:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { createFileIPLDDag } from '@autonomys/auto-drive'
|
|
43
|
+
import fs from 'fs'
|
|
44
|
+
|
|
45
|
+
const fileBuffer = fs.readFileSync('path/to/your/file.txt')
|
|
46
|
+
|
|
47
|
+
const dag = createFileIPLDDag(fileBuffer, 'file.txt')
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Creating an IPLD DAG from a Folder
|
|
51
|
+
|
|
52
|
+
To create an IPLD DAG from a folder, you can use the `createFolderIPLDDag` function:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { createFolderIPLDDag } from '@autonomys/auto-drive'
|
|
56
|
+
import { CID } from 'multiformats'
|
|
57
|
+
|
|
58
|
+
// Example child CIDs and folder information
|
|
59
|
+
const childCIDs: CID[] = [
|
|
60
|
+
/* array of CIDs */
|
|
61
|
+
]
|
|
62
|
+
const folderName = 'my-folder'
|
|
63
|
+
const folderSize = 1024 // size in bytes
|
|
64
|
+
|
|
65
|
+
const folderDag = createFolderIPLDDag(childCIDs, folderName, folderSize)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Working with CIDs
|
|
69
|
+
|
|
70
|
+
You can use functions from the `cid` module to work with CIDs:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { cidOfNode, cidToString, stringToCid } from '@autonomys/auto-drive'
|
|
74
|
+
|
|
75
|
+
// Create a CID from a node
|
|
76
|
+
const cid = cidOfNode(dag.head)
|
|
77
|
+
|
|
78
|
+
// Convert the CID to a string
|
|
79
|
+
const cidString = cidToString(cid)
|
|
80
|
+
|
|
81
|
+
// Parse a string back into a CID
|
|
82
|
+
const parsedCID = stringToCid(cidString)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Encoding and Decoding Nodes
|
|
86
|
+
|
|
87
|
+
You can encode and decode IPLD nodes:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { encodeNode, decodeNode } from '@autonomys/auto-drive'
|
|
91
|
+
|
|
92
|
+
// Encode a node
|
|
93
|
+
const encodedNode = encodeNode(dag.head)
|
|
94
|
+
|
|
95
|
+
// Decode a node
|
|
96
|
+
const decodedNode = decodeNode(encodedNode)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Handling Metadata
|
|
100
|
+
|
|
101
|
+
To add metadata to a node, you can create a metadata node:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { createMetadataNode } from '@autonomys/auto-drive'
|
|
105
|
+
|
|
106
|
+
const metadata = {
|
|
107
|
+
name: 'My File',
|
|
108
|
+
description: 'This is a sample file',
|
|
109
|
+
// ... other metadata fields
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const metadataNode = createMetadataNode(metadata)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Example: Creating a File DAG and Converting to CID
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { createFileIPLDDag, cidOfNode, cidToString } from '@autonomys/auto-drive'
|
|
119
|
+
import fs from 'fs'
|
|
120
|
+
|
|
121
|
+
const fileBuffer = fs.readFileSync('path/to/your/file.txt')
|
|
122
|
+
|
|
123
|
+
const dag = createFileIPLDDag(fileBuffer, 'file.txt')
|
|
124
|
+
|
|
125
|
+
const cid = cidOfNode(dag.headCID)
|
|
126
|
+
const cidString = cidToString(cid)
|
|
127
|
+
|
|
128
|
+
console.log(`CID of the file DAG: ${cidString}`)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
134
|
+
|
|
135
|
+
## Additional Resources
|
|
136
|
+
|
|
137
|
+
- **Autonomys Academy**: Learn more at [Autonomys Academy](https://academy.autonomys.xyz).
|
|
138
|
+
- **Auto-Utils Package**: Utility functions used alongside `auto-drive` can be found in [`@autonomys/auto-utils`](../Auto-Utils/README.md).
|
|
139
|
+
|
|
140
|
+
## Contact
|
|
141
|
+
|
|
142
|
+
If you have any questions or need support, feel free to reach out:
|
|
143
|
+
|
|
144
|
+
- **GitHub Issues**: [GitHub Issues Page](https://github.com/autonomys/auto-sdk/issues)
|
|
145
|
+
|
|
146
|
+
We appreciate your feedback and contributions!
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/metadata/offchain/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,OAAO,
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/metadata/offchain/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAEhE,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,SAAS,EAAE,CAAA;CACpB,CAAA;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,eAAO,MAAM,YAAY,QAClB,OAAO,aACD,MAAM,SACV,MAAM,aACF,MAAM,KAChB,oBAaF,CAAA"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { cidOfNode, cidToString
|
|
1
|
+
import { cidOfNode, cidToString } from '../../index.js';
|
|
2
2
|
export const fileMetadata = (dag, totalSize, name, mimeType) => {
|
|
3
|
-
const chunks = Array.from(dag.nodes.values()).filter((n) => n.Data && IPLDNodeData.decode(n.Data).data);
|
|
4
3
|
return {
|
|
5
4
|
type: 'file',
|
|
6
5
|
dataCid: cidToString(dag.headCID),
|
|
7
6
|
name,
|
|
8
7
|
mimeType,
|
|
9
8
|
totalSize,
|
|
10
|
-
totalChunks:
|
|
11
|
-
chunks:
|
|
9
|
+
totalChunks: dag.nodes.size,
|
|
10
|
+
chunks: Array.from(dag.nodes.values()).map((chunk) => {
|
|
12
11
|
var _a, _b;
|
|
13
12
|
return ({
|
|
14
13
|
cid: cidToString(cidOfNode(chunk)),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-drive",
|
|
3
3
|
"packageManager": "yarn@4.1.1",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"repository": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"protons": "^7.6.0",
|
|
40
40
|
"protons-runtime": "^5.5.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "68a54c6f18e51cb1f32a5997c04230a6107ab631"
|
|
43
43
|
}
|