Skip to content

Commit d93295a

Browse files
authored
chore: move mfs and multipart files into core (ipfs#2811)
BREAKING CHANGE: When the path passed to `ipfs.files.stat(path)` was a hamt sharded dir, the resovled value returned by js-ipfs previously had a `type` property of with a value of `'hamt-sharded-directory'`. To bring it in line with go-ipfs this value is now `'directory'`.
1 parent c41cd82 commit d93295a

File tree

127 files changed

+7748
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+7748
-204
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,6 @@ Listing of the main packages used in the IPFS ecosystem. There are also three sp
10161016
| [`ipfs-http-client`](//github.com/ipfs/js-ipfs) | [![npm](https://img.shields.io/npm/v/ipfs-http-client.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfs/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs/master)](https://travis-ci.com/ipfs/js-ipfs) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs) | [Alan Shaw](mailto:[email protected]) |
10171017
| [`ipfs-http-response`](//github.com/ipfs/js-ipfs-http-response) | [![npm](https://img.shields.io/npm/v/ipfs-http-response.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfs-http-response/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-http-response.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-http-response) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-http-response/master)](https://travis-ci.com/ipfs/js-ipfs-http-response) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-http-response/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-http-response) | [Vasco Santos](mailto:[email protected]) |
10181018
| [`ipfsd-ctl`](//github.com/ipfs/js-ipfsd-ctl) | [![npm](https://img.shields.io/npm/v/ipfsd-ctl.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfsd-ctl/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfsd-ctl.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfsd-ctl) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfsd-ctl/master)](https://travis-ci.com/ipfs/js-ipfsd-ctl) | [![codecov](https://codecov.io/gh/ipfs/js-ipfsd-ctl/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfsd-ctl) | [Hugo Dias](mailto:[email protected]) |
1019-
| [`ipfs-multipart`](//github.com/ipfs/js-ipfs) | [![npm](https://img.shields.io/npm/v/ipfs-multipart.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfs/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs/master)](https://travis-ci.com/ipfs/js-ipfs) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs) | [Hugo Dias](mailto:[email protected]) |
10201019
| [`is-ipfs`](//github.com/ipfs/is-ipfs) | [![npm](https://img.shields.io/npm/v/is-ipfs.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/is-ipfs/releases) | [![Deps](https://david-dm.org/ipfs/is-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/is-ipfs) | [![Travis CI](https://flat.badgen.net/travis/ipfs/is-ipfs/master)](https://travis-ci.com/ipfs/is-ipfs) | [![codecov](https://codecov.io/gh/ipfs/is-ipfs/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/is-ipfs) | [Marcin Rataj](mailto:[email protected]) |
10211020
| [`aegir`](//github.com/ipfs/aegir) | [![npm](https://img.shields.io/npm/v/aegir.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/aegir/releases) | [![Deps](https://david-dm.org/ipfs/aegir.svg?style=flat-square)](https://david-dm.org/ipfs/aegir) | [![Travis CI](https://flat.badgen.net/travis/ipfs/aegir/master)](https://travis-ci.com/ipfs/aegir) | [![codecov](https://codecov.io/gh/ipfs/aegir/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/aegir) | [Hugo Dias](mailto:[email protected]) |
10221021
| [`ipfs-repo-migrations`](//github.com/ipfs/js-ipfs-repo-migrations) | [![npm](https://img.shields.io/npm/v/ipfs-repo-migrations.svg?maxAge=86400&style=flat-square)](//github.com/ipfs/js-ipfs-repo-migrations/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-repo-migrations.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-repo-migrations) | [![Travis CI](https://flat.badgen.net/travis/ipfs/js-ipfs-repo-migrations/master)](https://travis-ci.com/ipfs/js-ipfs-repo-migrations) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-repo-migrations/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/ipfs/js-ipfs-repo-migrations) | N/A |

package-list.json

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
["ipfs/js-ipfs", "ipfs-http-client"],
3131
["ipfs/js-ipfs-http-response", "ipfs-http-response"],
3232
["ipfs/js-ipfsd-ctl", "ipfsd-ctl"],
33-
["ipfs/js-ipfs", "ipfs-multipart"],
3433
["ipfs/is-ipfs", "is-ipfs"],
3534
["ipfs/aegir", "aegir"],
3635
["ipfs/js-ipfs-repo-migrations", "ipfs-repo-migrations"],

package.json

+10-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
"test": "cross-env ECHO_SERVER_PORT=37480 aegir test",
4444
"test:node": "cross-env ECHO_SERVER_PORT=37481 aegir test -t node",
4545
"test:browser": "cross-env ECHO_SERVER_PORT=37482 aegir test -t browser",
46+
"test:browser:http": "cross-env ECHO_SERVER_PORT=37489 aegir test -t browser -f test/http-api/index.js",
47+
"test:browser:interface:http": "cross-env ECHO_SERVER_PORT=37489 aegir test -t browser -f test/http-api/interface.js",
4648
"test:webworker": "cross-env ECHO_SERVER_PORT=37483 aegir test -t webworker",
4749
"test:electron": "cross-env ECHO_SERVER_PORT=37484 aegir test -t electron-main -t electron-renderer",
4850
"test:electron-main": "cross-env ECHO_SERVER_PORT=37485 aegir test -t electron-main",
@@ -66,6 +68,7 @@
6668
"dependencies": {
6769
"@hapi/ammo": "^3.1.2",
6870
"@hapi/boom": "^7.4.3",
71+
"@hapi/content": "^4.1.0",
6972
"@hapi/hapi": "^18.4.0",
7073
"@hapi/joi": "^15.1.0",
7174
"abort-controller": "^3.0.0",
@@ -89,6 +92,7 @@
8992
"file-type": "^12.0.1",
9093
"fnv1a": "^1.0.1",
9194
"get-folder-size": "^2.0.0",
95+
"hamt-sharding": "^1.0.0",
9296
"hapi-pino": "^6.1.0",
9397
"hashlru": "^2.3.0",
9498
"interface-datastore": "^0.8.0",
@@ -97,8 +101,6 @@
97101
"ipfs-block-service": "^0.16.0",
98102
"ipfs-http-client": "^42.0.0",
99103
"ipfs-http-response": "^0.5.0",
100-
"ipfs-mfs": "^1.0.0",
101-
"ipfs-multipart": "^0.3.0",
102104
"ipfs-repo": "^0.30.1",
103105
"ipfs-unixfs": "^1.0.0",
104106
"ipfs-unixfs-exporter": "^1.0.1",
@@ -117,16 +119,17 @@
117119
"is-ipfs": "^0.6.1",
118120
"it-all": "^1.0.1",
119121
"it-concat": "^1.0.0",
122+
"it-drain": "^1.0.0",
120123
"it-glob": "0.0.7",
121124
"it-last": "^1.0.1",
125+
"it-map": "^1.0.0",
126+
"it-multipart": "^1.0.1",
122127
"it-pipe": "^1.1.0",
123128
"it-tar": "^1.2.1",
124129
"it-to-stream": "^0.1.1",
125130
"iterable-ndjson": "^1.1.0",
126131
"jsondiffpatch": "^0.3.11",
127132
"just-safe-set": "^2.1.0",
128-
"ky": "^0.15.0",
129-
"ky-universal": "^0.3.0",
130133
"libp2p": "^0.27.2",
131134
"libp2p-bootstrap": "^0.10.2",
132135
"libp2p-crypto": "^0.17.1",
@@ -172,19 +175,20 @@
172175
"yargs-promise": "^1.1.0"
173176
},
174177
"devDependencies": {
175-
"aegir": "^21.3.0",
178+
"aegir": "21.3.0",
176179
"base64url": "^3.0.1",
177180
"clear-module": "^4.0.0",
178181
"cross-env": "^7.0.0",
179182
"delay": "^4.3.0",
180183
"execa": "^3.0.0",
181184
"form-data": "^3.0.0",
182185
"go-ipfs-dep": "0.4.23-3",
183-
"hat": "0.0.3",
184186
"interface-ipfs-core": "^0.132.0",
185187
"ipfs-interop": "ipfs/interop#fix/name-pubsub",
186188
"ipfsd-ctl": "^3.0.0",
189+
"iso-random-stream": "^1.1.1",
187190
"it-first": "^1.0.1",
191+
"nanoid": "^2.1.11",
188192
"ncp": "^2.0.0",
189193
"p-event": "^4.1.0",
190194
"p-map": "^3.0.0",

src/cli/commands/files.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
module.exports = {
4+
command: 'files <command>',
5+
6+
description: 'Operations over mfs files (ls, mkdir, rm, etc)',
7+
8+
builder (yargs) {
9+
return yargs.commandDir('files')
10+
},
11+
12+
handler (argv) {
13+
argv.print('Type `jsipfs files --help` for more instructions')
14+
}
15+
}

src/cli/commands/files/chmod.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict'
2+
3+
const {
4+
asBoolean,
5+
asOctal
6+
} = require('../../utils')
7+
8+
module.exports = {
9+
command: 'chmod [mode] [path]',
10+
11+
describe: 'Change file modes',
12+
13+
builder: {
14+
path: {
15+
type: 'string',
16+
describe: 'The MFS path to change the mode of'
17+
},
18+
mode: {
19+
type: 'int',
20+
coerce: asOctal,
21+
describe: 'The mode to use'
22+
},
23+
recursive: {
24+
alias: 'r',
25+
type: 'boolean',
26+
default: false,
27+
coerce: asBoolean,
28+
describe: 'Whether to change modes recursively'
29+
},
30+
'hash-alg': {
31+
alias: 'h',
32+
type: 'string',
33+
default: 'sha2-256',
34+
describe: 'Hash function to use. Will set CID version to 1 if used'
35+
},
36+
flush: {
37+
alias: 'f',
38+
type: 'boolean',
39+
default: true,
40+
coerce: asBoolean,
41+
describe: 'Flush the changes to disk immediately'
42+
},
43+
'shard-split-threshold': {
44+
type: 'number',
45+
default: 1000,
46+
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory'
47+
}
48+
},
49+
50+
handler (argv) {
51+
const {
52+
ctx: { ipfs },
53+
path,
54+
mode,
55+
recursive,
56+
hashAlg,
57+
flush,
58+
shardSplitThreshold
59+
} = argv
60+
61+
return ipfs.files.chmod(path, mode, {
62+
recursive,
63+
hashAlg,
64+
flush,
65+
shardSplitThreshold
66+
})
67+
}
68+
}

src/cli/commands/files/cp.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict'
2+
3+
const {
4+
asBoolean
5+
} = require('../../utils')
6+
7+
module.exports = {
8+
command: 'cp <source> <dest>',
9+
10+
describe: 'Copy files between locations in the mfs',
11+
12+
builder: {
13+
parents: {
14+
alias: 'p',
15+
type: 'boolean',
16+
default: false,
17+
coerce: asBoolean,
18+
describe: 'Create any non-existent intermediate directories'
19+
},
20+
'hash-alg': {
21+
alias: 'h',
22+
type: 'string',
23+
default: 'sha2-256',
24+
describe: 'Hash function to use. Will set CID version to 1 if used'
25+
},
26+
flush: {
27+
alias: 'f',
28+
type: 'boolean',
29+
default: true,
30+
coerce: asBoolean,
31+
describe: 'Flush the changes to disk immediately'
32+
},
33+
'shard-split-threshold': {
34+
type: 'number',
35+
default: 1000,
36+
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory'
37+
}
38+
},
39+
40+
handler (argv) {
41+
const {
42+
ctx: { ipfs },
43+
source,
44+
dest,
45+
parents,
46+
flush,
47+
hashAlg,
48+
shardSplitThreshold
49+
} = argv
50+
51+
return ipfs.files.cp(source, dest, {
52+
parents,
53+
flush,
54+
hashAlg,
55+
shardSplitThreshold
56+
})
57+
}
58+
}

src/cli/commands/files/flush.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict'
2+
3+
module.exports = {
4+
command: 'flush [path]',
5+
6+
describe: ' Flush a given path\'s data to disk',
7+
8+
builder: {
9+
'cid-base': {
10+
describe: 'CID base to use.'
11+
}
12+
},
13+
14+
async handler (argv) {
15+
const {
16+
ctx: { ipfs, print },
17+
path,
18+
cidBase
19+
} = argv
20+
21+
let cid = await ipfs.files.flush(path || '/', {})
22+
23+
if (cidBase && cidBase !== 'base58btc' && cid.version === 0) {
24+
cid = cid.toV1()
25+
}
26+
27+
print(JSON.stringify({
28+
Cid: cid.toString(cidBase)
29+
}))
30+
}
31+
}

src/cli/commands/files/ls.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict'
2+
3+
const all = require('it-all')
4+
const {
5+
asBoolean
6+
} = require('../../utils')
7+
const formatMode = require('ipfs-utils/src/files/format-mode')
8+
const formatMtime = require('ipfs-utils/src/files/format-mtime')
9+
10+
module.exports = {
11+
command: 'ls [path]',
12+
13+
describe: 'List mfs directories',
14+
15+
builder: {
16+
long: {
17+
alias: 'l',
18+
type: 'boolean',
19+
default: false,
20+
coerce: asBoolean,
21+
describe: 'Use long listing format.'
22+
},
23+
sort: {
24+
alias: 's',
25+
type: 'boolean',
26+
default: true,
27+
coerce: asBoolean,
28+
describe: 'Sort entries by name'
29+
},
30+
'cid-base': {
31+
describe: 'CID base to use.'
32+
}
33+
},
34+
35+
async handler (argv) {
36+
const {
37+
ctx: { ipfs, print },
38+
path,
39+
long,
40+
sort,
41+
cidBase
42+
} = argv
43+
44+
const printListing = file => {
45+
if (long) {
46+
print(`${formatMode(file.mode, file.type === 1)}\t${formatMtime(file.mtime)}\t${file.name}\t${file.cid.toString(cidBase)}\t${file.size}`)
47+
} else {
48+
print(file.name)
49+
}
50+
}
51+
52+
// https://github.com/ipfs/go-ipfs/issues/5181
53+
if (sort) {
54+
let files = await all(ipfs.files.ls(path || '/'))
55+
56+
files = files.sort((a, b) => {
57+
return a.name.localeCompare(b.name)
58+
})
59+
60+
files.forEach(printListing)
61+
return
62+
}
63+
64+
for await (const file of ipfs.files.ls(path || '/')) {
65+
printListing(file)
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)