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
-[Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify--webpack-or-any-other-bundler)
30
-
-[Use in a browser Using a script tag](#use-in-a-browser-using-a-script-tag)
31
-
-[Usage](#usage)
32
-
-[Examples](#examples)
33
-
-[Create a file composed by several blocks](#create-a-file-composed-by-several-blocks)
34
-
-[Create a directory that contains several files](#create-a-directory-that-contains-several-files)
35
-
-[API](#api)
36
-
-[unixfs Data Structure](#unixfs-data-structure)
37
-
-[create an unixfs Data element](#create-an-unixfs-data-element)
38
-
-[add and remove a block size to the block size list](#add-and-remove-a-block-size-to-the-block-size-list)
39
-
-[get total fileSize](#get-total-filesize)
40
-
-[marshal and unmarshal](#marshal-and-unmarshal)
41
-
-[Contribute](#contribute)
42
-
-[License](#license)
21
+
## Table of Contents <!-- omit in toc -->
22
+
23
+
-[Install](#install)
24
+
-[npm](#npm)
25
+
-[Use in Node.js](#use-in-nodejs)
26
+
-[Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)
27
+
-[Use in a browser Using a script tag](#use-in-a-browser-using-a-script-tag)
28
+
-[Usage](#usage)
29
+
-[Examples](#examples)
30
+
-[Create a file composed by several blocks](#create-a-file-composed-by-several-blocks)
31
+
-[Create a directory that contains several files](#create-a-directory-that-contains-several-files)
32
+
-[API](#api)
33
+
-[unixfs Data Structure](#unixfs-data-structure)
34
+
-[create an unixfs Data element](#create-an-unixfs-data-element)
35
+
-[add and remove a block size to the block size list](#add-and-remove-a-block-size-to-the-block-size-list)
36
+
-[get total fileSize](#get-total-filesize)
37
+
-[marshal and unmarshal](#marshal-and-unmarshal)
38
+
-[Contribute](#contribute)
39
+
-[License](#license)
43
40
44
41
## Install
45
42
@@ -80,7 +77,7 @@ Loading this module through a script tag will make the `Unixfs` obj available in
80
77
#### Create a file composed by several blocks
81
78
82
79
```JavaScript
83
-
var data =newUnixfs('file')
80
+
constdata=newUnixfs({ type:'file' })
84
81
data.addBlockSize(256) // add the size of each block
85
82
data.addBlockSize(256)
86
83
// ...
@@ -91,14 +88,16 @@ data.addBlockSize(256)
91
88
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.
92
89
93
90
```JavaScript
94
-
var data =newUnixfs('directory')
91
+
constdata=newUnixfs({ type:'directory' })
95
92
```
96
93
97
94
## API
98
95
99
96
#### unixfs Data Structure
100
97
101
98
```protobuf
99
+
syntax = "proto2";
100
+
102
101
message Data {
103
102
enum DataType {
104
103
Raw = 0;
@@ -113,23 +112,36 @@ message Data {
113
112
optional bytes Data = 2;
114
113
optional uint64 filesize = 3;
115
114
repeated uint64 blocksizes = 4;
116
-
117
115
optional uint64 hashType = 5;
118
116
optional uint64 fanout = 6;
117
+
optional uint32 mode = 7;
118
+
optional int64 mtime = 8;
119
119
}
120
120
121
121
message Metadata {
122
-
optional string MimeType = 1;
122
+
required string MimeType = 1;
123
123
}
124
124
```
125
125
126
126
#### create an unixfs Data element
127
127
128
128
```JavaScript
129
-
var data =newUnixFS(<type>, [<content>])
129
+
constdata=newUnixFS([options])
130
130
```
131
131
132
-
Type can be: `['raw', 'directory', 'file', 'metadata', 'symlink', 'hamt-sharded-directory']`
132
+
`options` is an optional object argument that might include the following keys:
133
+
134
+
- type (string, default `file`): The type of UnixFS node. Can be:
135
+
-`raw`
136
+
-`directory`
137
+
-`file`
138
+
-`metadata`
139
+
-`symlink`
140
+
-`hamt-sharded-directory`
141
+
- data (Buffer): The optional data field for this node
142
+
- blockSizes (Array, default: `[]`): If this is a `file` node that is made up of multiple blocks, `blockSizes` is a list numbers that represent the size of the file chunks stored in each child node. It is used to calculate the total file size.
143
+
- mode (Number, default `0644` for files, `0755` for directories/hamt-sharded-directories) file mode
144
+
- mtime (Date, default `0`): The modification time of this node
133
145
134
146
#### add and remove a block size to the block size list
135
147
@@ -149,9 +161,9 @@ data.fileSize() // => size in bytes
0 commit comments