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
{{ message }}
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
docs: add mode and mtime and .touch/.chmod mfs commands (#572)
* docs: add mode and mtime and .touch/.chmod mfs commands
* docs: update arg/return types
* test: updates tests to use timespecs
* fix: remove cumulativeSize as it changes based on timestamps
* docs: update SPEC/FILES.md
* docs: update SPEC/FILES.md
* docs: remove format
* Update SPEC/FILES.md
Co-Authored-By: Steven Allen <steven@stebalien.com>
* docs: more detail about mtime values
* docs: remove octal as string
* docs: remove mode as strings
* fix: fix up tests for optional mtime
Co-authored-by: Steven Allen <steven@stebalien.com>
content:<data>// A Buffer, Readable Stream, Pull Stream or File with the contents of the file
63
+
mode:<Number>// optional integer mode to store the entry with
64
+
mtime:<time>// optional value representing the modification time of the entry - either a `Date` object, an object with `{ secs, nsecs }` properties where `secs` is the number of seconds since (positive) or before (negative) the Unix Epoch began and `nsecs` is the number of nanoseconds since the last full second, or the output of `process.hrtime()`
61
65
}
62
66
```
63
67
If no `content` is passed, then the path is treated as an empty directory
@@ -98,6 +102,8 @@ an array of objects is returned, each of the form:
@@ -179,6 +189,8 @@ stream.on('data', function (file) {
179
189
// {
180
190
// path: '/tmp/myfile.txt',
181
191
// hash: 'QmHash' // base58 encoded multihash
192
+
// mode: Number,
193
+
// mtime: { secs: Number, nsecs: Number },
182
194
// size: 123
183
195
// }
184
196
})
@@ -207,6 +219,8 @@ Returns a Pull Stream, where objects can be written of the forms
207
219
{
208
220
path:'/tmp/myfile.txt', // The file path
209
221
content:<data>// A Buffer, Readable Stream, Pull Stream or File with the contents of the file
222
+
mode:<Number>// optional integer mode to store the entry with
223
+
mtime:<time>// optional value representing the modification time of the entry - either a `Date` object, an object with `{ secs, nsecs }` properties where `secs` is the number of seconds since (positive) or before (negative) the Unix Epoch began and `nsecs` is the number of nanoseconds since the last full second, or the output of `process.hrtime()`
210
224
}
211
225
```
212
226
@@ -233,6 +247,8 @@ pull(
233
247
// {
234
248
// path: '/tmp/myfile.txt',
235
249
// hash: 'QmHash' // base58 encoded multihash
250
+
// mode: Number
251
+
// mtime: { secs: Number, nsecs: Number }
236
252
// size: 123
237
253
// }
238
254
})
@@ -264,6 +280,8 @@ an array of objects is returned, each of the form:
@@ -759,6 +789,46 @@ A great source of [examples][] can be found in the tests for this API.
759
789
760
790
The Mutable File System (MFS) is a virtual file system on top of IPFS that exposes a Unix like API over a virtual directory. It enables users to write and read from paths without having to worry about updating the graph. It enables things like [ipfs-blob-store](https://github.com/ipfs/ipfs-blob-store) to exist.
761
791
792
+
#### `files.chmod`
793
+
794
+
> Change mode for files and directories
795
+
796
+
##### `ipfs.files.chmod(path, mode, [options])`
797
+
798
+
Where:
799
+
800
+
-`path` is the path to the entry to modify. It might be:
801
+
- An existing MFS path to a file or a directory (e.g. `/my-dir/my-file.txt`)
802
+
- An IPFS path (e.g. `/ipfs/QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks`)
803
+
- A [CID][cid] instance (e.g. `new CID('QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks')`)
804
+
-`mode` is the new file mode. It might be:
805
+
- A string modification of the existing mode, e.g. `'a+x'`, `'g-w'`, etc
806
+
- An integer, e.g. the returned value from `parseInt('0755', 8)` or `0o755`
807
+
-`options` is an optional Object that might contain the following keys:
808
+
-`recursive` is a Boolean value that indicates if `mode` should be applied to all sub files/directories of `path` (default: false)
809
+
-`hashAlg` is which algorithm to use when creating CIDs for modified entries. (default: `sha2-256`) [The list of all possible values](https://github.com/multiformats/js-multihash/blob/master/src/constants.js#L5-L343)
810
+
-`flush` is a Boolean value to decide whether or not to immediately flush MFS changes to disk (default: true)
811
+
-`cidVersion`: the CID version to use for any updated entries (integer, default 0)
812
+
813
+
**Returns**
814
+
815
+
| Type | Description |
816
+
| -------- | -------- |
817
+
|`Promise<void>`| If action is successfully completed. Otherwise an error will be thrown |
-`parents` is a Boolean value to decide whether or not to make the parent directories if they don't exist (default: false)
820
890
-`hashAlg` is which algorithm to use when creating CIDs for newly created directories (default: `sha2-256`) [The list of all possible values](https://github.com/multiformats/js-multihash/blob/master/src/constants.js#L5-L343)
821
891
-`flush` is a Boolean value to decide whether or not to immediately flush MFS changes to disk (default: true)
892
+
-`mode`: optional UnixFS mode to create the directory with - a number or a string that will be interpreted as a base 8 number
893
+
-`mtime`: A Date object, an object with `{ secs, nsecs }` properties where `secs` is the number of seconds since (positive) or before (negative) the Unix Epoch began and `nsecs` is the number of nanoseconds since the last full second, or the output of [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime_time)
822
894
823
895
**Returns**
824
896
@@ -882,6 +954,42 @@ console.log(stats)
882
954
// }
883
955
```
884
956
957
+
#### `files.touch`
958
+
959
+
> Update the mtime of a file or directory
960
+
961
+
##### `ipfs.files.touch(path, [options])`
962
+
963
+
Where:
964
+
965
+
-`path` is the path to the file or directory to update. It might be:
966
+
- An existing MFS path to a file or directory (e.g. `/my-dir/a.txt`)
967
+
- An IPFS path (e.g. `/ipfs/QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks`)
968
+
- A [CID][cid] instance (e.g. `new CID('QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks')`)
969
+
-`options` is an optional Object that might contain the following keys:
970
+
-`mtime` Either a ` Date` object, an object with `{ sec, nsecs }` properties or the output of `process.hrtime()` (default: now)
971
+
-`hashAlg` is which algorithm to use when creating CIDs for modified entries. (default: `sha2-256`) [The list of all possible values](https://github.com/multiformats/js-multihash/blob/master/src/constants.js#L5-L343)
972
+
-`flush` is a Boolean value to decide whether or not to immediately flush MFS changes to disk (default: true)
973
+
-`cidVersion`: the CID version to use for any updated entries (integer, default 0)
974
+
975
+
**Returns**
976
+
977
+
| Type | Description |
978
+
| -------- | -------- |
979
+
|`Promise<void>`| If action is successfully completed. Otherwise an error will be thrown |
980
+
981
+
**Example:**
982
+
983
+
```JavaScript
984
+
// set the mtime to the current time
985
+
awaitipfs.files.touch('/path/to/file.txt')
986
+
987
+
// set the mtime to a specific time
988
+
awaitipfs.files.touch('/path/to/file.txt', {
989
+
mtime:newDate('May 23, 2014 14:45:14 -0700')
990
+
})
991
+
```
992
+
885
993
#### `files.rm`
886
994
887
995
> Remove a file or directory.
@@ -1034,6 +1142,8 @@ Where:
1034
1142
-`length` is an Integer with the maximum number of bytes to read (default: Read all bytes from `content`)
1035
1143
-`rawLeaves`: if true, DAG leaves will contain raw file data and not be wrapped in a protobuf (boolean, default false)
1036
1144
-`cidVersion`: the CID version to use when storing the data (storage keys are based on the CID, including its version) (integer, default 0)
1145
+
-`mode`: optional UnixFS mode to create or update the file with - a number or a string that will be interpreted as a base 8 number
1146
+
-`mtime`: A Date object, an object with `{ sec, nsecs }` properties or the output of `process.hrtime()` or `process.hrtime.bigint()`
1037
1147
1038
1148
**Returns**
1039
1149
@@ -1141,6 +1251,8 @@ each object contains the following keys:
1141
1251
-`type` which is the object's type (`directory` or `file`)
1142
1252
-`size` the size of the file in bytes
1143
1253
-`hash` the hash of the file
1254
+
-`mode` the UnixFS mode as a Number
1255
+
-`mtime` an objects with numeric `secs` and `nsecs` properties
1144
1256
1145
1257
**Example:**
1146
1258
@@ -1185,6 +1297,8 @@ the yielded objects contain the following keys:
1185
1297
-`type` which is the object's type (`directory` or `file`)
1186
1298
-`size` the size of the file in bytes
1187
1299
-`hash` the hash of the file
1300
+
-`mode` the UnixFS mode as a Number
1301
+
-`mtime` an object with numeric `secs` and `nsecs` properties
1188
1302
1189
1303
**Example:**
1190
1304
@@ -1227,6 +1341,8 @@ the yielded objects contain the following keys:
1227
1341
-`type` which is the object's type (`directory` or `file`)
1228
1342
-`size` the size of the file in bytes
1229
1343
-`hash` the hash of the file
1344
+
-`mode` the UnixFS mode as a Number
1345
+
-`mtime` an object with numeric `secs` and `nsecs` properties
0 commit comments