You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/ipfs-unixfs/README.md
+46-19Lines changed: 46 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,25 +30,33 @@ The UnixFS spec can be found in the [ipfs/specs repository](http://github.com/ip
30
30
31
31
## Example - Create a file composed of several blocks
32
32
33
-
```JavaScript
33
+
```TypeScript
34
+
import { UnixFS } from'ipfs-unixfs'
35
+
34
36
const data =newUnixFS({ type: 'file' })
35
-
data.addBlockSize(256) // add the size of each block
36
-
data.addBlockSize(256)
37
+
data.addBlockSize(256n) // add the size of each block
38
+
data.addBlockSize(256n)
37
39
// ...
38
40
```
39
41
40
42
## Example - Create a directory that contains several files
41
43
42
44
Creating a directory that contains several files is achieve by creating a unixfs element that identifies a MerkleDAG node as a directory. The links of that MerkleDAG node are the files that are contained in this directory.
43
45
44
-
```JavaScript
46
+
```TypeScript
47
+
import { UnixFS } from'ipfs-unixfs'
48
+
45
49
const data =newUnixFS({ type: 'directory' })
46
50
```
47
51
48
52
## Example - Create an unixfs Data element
49
53
50
-
```JavaScript
51
-
constdata=newUnixFS([options])
54
+
```TypeScript
55
+
import { UnixFS } from'ipfs-unixfs'
56
+
57
+
const data =newUnixFS({
58
+
// ...options
59
+
})
52
60
```
53
61
54
62
`options` is an optional object argument that might include the following keys:
@@ -67,48 +75,67 @@ const data = new UnixFS([options])
67
75
68
76
## Example - Add and remove a block size to the block size list
69
77
70
-
```JavaScript
71
-
data.addBlockSize(<size in bytes>)
78
+
```TypeScript
79
+
import { UnixFS } from'ipfs-unixfs'
80
+
81
+
const data =newUnixFS({ type: 'file' })
82
+
const sizeInBytes =100n
83
+
data.addBlockSize(sizeInBytes)
72
84
```
73
85
74
-
```JavaScript
75
-
data.removeBlockSize(<index>)
86
+
```TypeScript
87
+
import { UnixFS } from'ipfs-unixfs'
88
+
89
+
const data =newUnixFS({ type: 'file' })
90
+
91
+
const index =0
92
+
data.removeBlockSize(index)
76
93
```
77
94
78
95
## Example - Get total fileSize
79
96
80
-
```JavaScript
97
+
```TypeScript
98
+
import { UnixFS } from'ipfs-unixfs'
99
+
100
+
const data =newUnixFS({ type: 'file' })
81
101
data.fileSize() // => size in bytes
82
102
```
83
103
84
104
## Example - Marshal and unmarshal
85
105
86
-
```javascript
106
+
```TypeScript
107
+
import { UnixFS } from'ipfs-unixfs'
108
+
109
+
const data =newUnixFS({ type: 'file' })
87
110
const marshaled =data.marshal()
88
-
constunmarshaled=Unixfs.unmarshal(marshaled)
111
+
const unmarshaled =UnixFS.unmarshal(marshaled)
89
112
```
90
113
91
114
## Example - Is this UnixFS entry a directory?
92
115
93
-
```JavaScript
94
-
constdir=newData({ type:'directory' })
116
+
```TypeScript
117
+
import { UnixFS } from'ipfs-unixfs'
118
+
119
+
const dir =newUnixFS({ type: 'directory' })
95
120
dir.isDirectory() // true
96
121
97
-
constfile=newData({ type:'file' })
122
+
const file =newUnixFS({ type: 'file' })
98
123
file.isDirectory() // false
99
124
```
100
125
101
126
## Example - Has an mtime been set?
102
127
103
128
If no modification time has been set, no `mtime` property will be present on the `Data` instance:
0 commit comments