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
+
-[is this UnixFS entry a directory?](#is-this-unixfs-entry-a-directory)
39
+
-[Contribute](#contribute)
40
+
-[License](#license)
43
41
44
42
## Install
45
43
@@ -52,20 +50,20 @@
52
50
### Use in Node.js
53
51
54
52
```JavaScript
55
-
varUnixfs=require('ipfs-unixfs')
53
+
varUnixFS=require('ipfs-unixfs')
56
54
```
57
55
58
56
### Use in a browser with browserify, webpack or any other bundler
59
57
60
58
The code published to npm that gets loaded on require is in fact a ES5 transpiled version with the right shims added. This means that you can require it and use with your favourite bundler without having to adjust asset management process.
61
59
62
60
```JavaScript
63
-
varUnixfs=require('ipfs-unixfs')
61
+
varUnixFS=require('ipfs-unixfs')
64
62
```
65
63
66
64
### Use in a browser Using a script tag
67
65
68
-
Loading this module through a script tag will make the `Unixfs` obj available in the global namespace.
66
+
Loading this module through a script tag will make the `UnixFS` obj available in the global namespace.
@@ -80,7 +78,7 @@ Loading this module through a script tag will make the `Unixfs` obj available in
80
78
#### Create a file composed by several blocks
81
79
82
80
```JavaScript
83
-
var data =newUnixfs('file')
81
+
constdata=newUnixFS({ type:'file' })
84
82
data.addBlockSize(256) // add the size of each block
85
83
data.addBlockSize(256)
86
84
// ...
@@ -91,14 +89,16 @@ data.addBlockSize(256)
91
89
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
90
93
91
```JavaScript
94
-
var data =newUnixfs('directory')
92
+
constdata=newUnixFS({ type:'directory' })
95
93
```
96
94
97
95
## API
98
96
99
-
#### unixfs Data Structure
97
+
#### UnixFS Data Structure
100
98
101
99
```protobuf
100
+
syntax = "proto2";
101
+
102
102
message Data {
103
103
enum DataType {
104
104
Raw = 0;
@@ -113,9 +113,10 @@ message Data {
113
113
optional bytes Data = 2;
114
114
optional uint64 filesize = 3;
115
115
repeated uint64 blocksizes = 4;
116
-
117
116
optional uint64 hashType = 5;
118
117
optional uint64 fanout = 6;
118
+
optional uint32 mode = 7;
119
+
optional int64 mtime = 8;
119
120
}
120
121
121
122
message Metadata {
@@ -126,10 +127,22 @@ message Metadata {
126
127
#### create an unixfs Data element
127
128
128
129
```JavaScript
129
-
var data =newUnixFS(<type>, [<content>])
130
+
constdata=newUnixFS([options])
130
131
```
131
132
132
-
Type can be: `['raw', 'directory', 'file', 'metadata', 'symlink', 'hamt-sharded-directory']`
133
+
`options` is an optional object argument that might include the following keys:
134
+
135
+
- type (string, default `file`): The type of UnixFS entry. Can be:
136
+
-`raw`
137
+
-`directory`
138
+
-`file`
139
+
-`metadata`
140
+
-`symlink`
141
+
-`hamt-sharded-directory`
142
+
- data (Buffer): The optional data field for this node
143
+
- 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.
144
+
- mode (Number, default `0644` for files, `0755` for directories/hamt-sharded-directories) file mode
145
+
- mtime (Date, default `0`): The modification time of this node
133
146
134
147
#### add and remove a block size to the block size list
135
148
@@ -149,9 +162,19 @@ data.fileSize() // => size in bytes
0 commit comments