Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 009fb98

Browse files
authored
fix: remove format and/or codec options (#69)
IPFS is all `dag-pb` yet we allow passing `dag-cbor` as the format of IPLD node to use. This is likely to break anything that uses it as tools expect IPFS stuff to be `dag-pb`, possibly with `raw` leaves. Closes #67 BREAKING CHANGE: `--format` and/or `--codec` option has been removed from the CLI, the HTTP API and the core API.
1 parent 38a8b51 commit 009fb98

39 files changed

+14
-383
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"ipfs-multipart": "^0.3.0",
7474
"ipfs-unixfs": "^0.3.0",
7575
"ipfs-unixfs-exporter": "^0.40.0",
76-
"ipfs-unixfs-importer": "^0.43.0",
76+
"ipfs-unixfs-importer": "^0.43.1",
7777
"ipfs-utils": "^0.4.2",
7878
"ipld-dag-pb": "^0.18.0",
7979
"it-last": "^1.0.1",

Diff for: src/cli/chmod.js

-8
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ module.exports = {
2727
coerce: asBoolean,
2828
describe: 'Whether to change modes recursively'
2929
},
30-
codec: {
31-
alias: 'c',
32-
type: 'string',
33-
default: 'dag-pb',
34-
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
35-
},
3630
'hash-alg': {
3731
alias: 'h',
3832
type: 'string',
@@ -59,7 +53,6 @@ module.exports = {
5953
mode,
6054
getIpfs,
6155
recursive,
62-
codec,
6356
hashAlg,
6457
flush,
6558
shardSplitThreshold
@@ -70,7 +63,6 @@ module.exports = {
7063

7164
return ipfs.files.chmod(path, mode, {
7265
recursive,
73-
format: codec,
7466
hashAlg,
7567
flush,
7668
shardSplitThreshold

Diff for: src/cli/cp.js

-8
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ module.exports = {
1717
coerce: asBoolean,
1818
describe: 'Create any non-existent intermediate directories'
1919
},
20-
codec: {
21-
alias: 'c',
22-
type: 'string',
23-
default: 'dag-pb',
24-
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
25-
},
2620
'hash-alg': {
2721
alias: 'h',
2822
type: 'string',
@@ -49,7 +43,6 @@ module.exports = {
4943
dest,
5044
getIpfs,
5145
parents,
52-
codec,
5346
flush,
5447
hashAlg,
5548
shardSplitThreshold
@@ -59,7 +52,6 @@ module.exports = {
5952
const ipfs = await getIpfs()
6053
return ipfs.files.cp(source, dest, {
6154
parents,
62-
format: codec,
6355
flush,
6456
hashAlg,
6557
shardSplitThreshold

Diff for: src/cli/mkdir.js

-8
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ module.exports = {
2525
default: 0,
2626
describe: 'Cid version to use. (experimental).'
2727
},
28-
codec: {
29-
alias: 'c',
30-
type: 'string',
31-
default: 'dag-pb',
32-
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
33-
},
3428
'hash-alg': {
3529
alias: 'h',
3630
type: 'string',
@@ -67,7 +61,6 @@ module.exports = {
6761
getIpfs,
6862
parents,
6963
cidVersion,
70-
codec,
7164
hashAlg,
7265
flush,
7366
shardSplitThreshold,
@@ -81,7 +74,6 @@ module.exports = {
8174
return ipfs.files.mkdir(path, {
8275
parents,
8376
cidVersion,
84-
format: codec,
8577
hashAlg,
8678
flush,
8779
shardSplitThreshold,

Diff for: src/cli/mv.js

-8
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ module.exports = {
3030
default: 0,
3131
describe: 'Cid version to use. (experimental).'
3232
},
33-
codec: {
34-
alias: 'c',
35-
type: 'string',
36-
default: 'dag-pb',
37-
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
38-
},
3933
'hash-alg': {
4034
alias: 'h',
4135
type: 'string',
@@ -64,7 +58,6 @@ module.exports = {
6458
parents,
6559
recursive,
6660
cidVersion,
67-
codec,
6861
hashAlg,
6962
flush,
7063
shardSplitThreshold
@@ -77,7 +70,6 @@ module.exports = {
7770
parents,
7871
recursive,
7972
cidVersion,
80-
format: codec,
8173
hashAlg,
8274
flush,
8375
shardSplitThreshold

Diff for: src/cli/touch.js

-8
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ module.exports = {
3131
default: 0,
3232
describe: 'Cid version to use. (experimental).'
3333
},
34-
codec: {
35-
alias: 'c',
36-
type: 'string',
37-
default: 'dag-pb',
38-
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
39-
},
4034
'hash-alg': {
4135
alias: 'h',
4236
type: 'string',
@@ -56,7 +50,6 @@ module.exports = {
5650
getIpfs,
5751
flush,
5852
cidVersion,
59-
codec,
6053
hashAlg,
6154
shardSplitThreshold,
6255
mtime
@@ -69,7 +62,6 @@ module.exports = {
6962
mtime,
7063
flush,
7164
cidVersion,
72-
format: codec,
7365
hashAlg,
7466
shardSplitThreshold
7567
})

Diff for: src/cli/write.js

-7
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ module.exports = {
7878
type: 'string',
7979
default: 'sha2-256'
8080
},
81-
codec: {
82-
alias: ['c'],
83-
type: 'string',
84-
default: 'dag-pb'
85-
},
8681
'shard-split-threshold': {
8782
type: 'number',
8883
default: 1000,
@@ -114,7 +109,6 @@ module.exports = {
114109
reduceSingleLeafToSelf,
115110
cidVersion,
116111
hashAlg,
117-
codec,
118112
parents,
119113
progress,
120114
strategy,
@@ -136,7 +130,6 @@ module.exports = {
136130
reduceSingleLeafToSelf,
137131
cidVersion,
138132
hashAlg,
139-
format: codec,
140133
parents,
141134
progress,
142135
strategy,

Diff for: src/core/chmod.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const mh = require('multihashes')
1616
const defaultOptions = {
1717
flush: true,
1818
shardSplitThreshold: 1000,
19-
format: 'dag-pb',
2019
hashAlg: 'sha2-256',
2120
cidVersion: 0,
2221
recursive: false
@@ -174,7 +173,7 @@ module.exports = (context) => {
174173

175174
const updatedCid = await context.ipld.put(node, mc.DAG_PB, {
176175
cidVersion: cid.version,
177-
hashAlg: mh.names['sha2-256'],
176+
hashAlg: mh.names[options.hashAlg],
178177
onlyHash: !options.flush
179178
})
180179

@@ -188,8 +187,7 @@ module.exports = (context) => {
188187
cid: updatedCid,
189188
size: node.serialize().length,
190189
flush: options.flush,
191-
format: 'dag-pb',
192-
hashAlg: 'sha2-256',
190+
hashAlg: options.hashAlg,
193191
cidVersion: cid.version
194192
})
195193

Diff for: src/core/cp.js

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const toTrail = require('./utils/to-trail')
1515
const defaultOptions = {
1616
parents: false,
1717
flush: true,
18-
format: 'dag-pb',
1918
hashAlg: 'sha2-256',
2019
cidVersion: 0,
2120
shardSplitThreshold: 1000
@@ -150,7 +149,6 @@ const addSourceToParent = async (context, source, childName, parent, options) =>
150149
size: sourceBlock.data.length,
151150
cid: source.cid,
152151
name: childName,
153-
format: options.format,
154152
hashAlg: options.hashAlg,
155153
cidVersion: options.cidVersion,
156154
flush: options.flush

Diff for: src/core/mkdir.js

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const defaultOptions = {
1919
hashAlg: 'sha2-256',
2020
cidVersion: 0,
2121
shardSplitThreshold: 1000,
22-
format: 'dag-pb',
2322
flush: true,
2423
mode: null,
2524
mtime: null
@@ -116,7 +115,6 @@ const addEmptyDir = async (context, childName, emptyDir, parent, trail, options)
116115
size: emptyDir.node.size,
117116
cid: emptyDir.cid,
118117
name: childName,
119-
format: options.format,
120118
hashAlg: options.hashAlg,
121119
cidVersion: options.cidVersion,
122120
mode: options.mode,

Diff for: src/core/mv.js

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const defaultOptions = {
1010
recursive: false,
1111
flush: true,
1212
cidVersion: 0,
13-
format: 'dag-pb',
1413
hashAlg: 'sha2-256',
1514
shardSplitThreshold: 1000
1615
}

Diff for: src/core/rm.js

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const defaultOptions = {
1616
recursive: false,
1717
cidVersion: 0,
1818
hashAlg: 'sha2-256',
19-
format: 'dag-pb',
2019
flush: true
2120
}
2221

@@ -64,7 +63,6 @@ const removePath = async (context, path, options) => {
6463
} = await removeLink(context, {
6564
parentCid: parent.cid,
6665
name: child.name,
67-
format: options.format,
6866
hashAlg: options.hashAlg,
6967
cidVersion: options.cidVersion,
7068
flush: options.flush

Diff for: src/core/touch.js

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const defaultOptions = {
1818
flush: true,
1919
shardSplitThreshold: 1000,
2020
cidVersion: 0,
21-
format: 'dag-pb',
2221
hashAlg: 'sha2-256'
2322
}
2423

@@ -85,7 +84,6 @@ module.exports = (context) => {
8584
size: node.serialize().length,
8685
flush: options.flush,
8786
shardSplitThreshold: options.shardSplitThreshold,
88-
format: 'dag-pb',
8987
hashAlg: 'sha2-256',
9088
cidVersion
9189
})

Diff for: src/core/utils/add-link.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,10 @@ const addToDirectory = async (context, options) => {
9999
node.mtime = new Date()
100100
options.parent = new DAGNode(node.marshal(), options.parent.Links)
101101

102-
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
103102
const hashAlg = mh.names[options.hashAlg]
104103

105104
// Persist the new parent DAGNode
106-
const cid = await context.ipld.put(options.parent, format, {
105+
const cid = await context.ipld.put(options.parent, mc.DAG_PB, {
107106
cidVersion: options.cidVersion,
108107
hashAlg,
109108
onlyHash: !options.flush

Diff for: src/core/utils/apply-default-options.js

-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ module.exports = (options = {}, defaults) => {
1717
}
1818
}
1919

20-
const format = output.format || output.codec
21-
22-
if (format && isNaN(format)) {
23-
output.format = format
24-
delete output.codec
25-
}
26-
2720
// support legacy go arguments
2821
if (options.count !== undefined) {
2922
output.length = options.count

Diff for: src/core/utils/create-node.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const mc = require('multicodec')
88
const mh = require('multihashes')
99

1010
const createNode = async (context, type, options) => {
11-
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
1211
const hashAlg = mh.names[options.hashAlg]
1312
const metadata = new UnixFS({
1413
type,
@@ -17,7 +16,7 @@ const createNode = async (context, type, options) => {
1716
})
1817

1918
const node = new DAGNode(metadata.marshal())
20-
const cid = await context.ipld.put(node, format, {
19+
const cid = await context.ipld.put(node, mc.DAG_PB, {
2120
cidVersion: options.cidVersion,
2221
hashAlg,
2322
onlyHash: !options.flush

Diff for: src/core/utils/hamt-utils.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ const updateHamtDirectory = async (context, links, bucket, options) => {
2424
mtime: node.mtime
2525
})
2626

27-
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
2827
const hashAlg = mh.names[options.hashAlg]
29-
3028
const parent = new DAGNode(dir.marshal(), links)
31-
const cid = await context.ipld.put(parent, format, {
29+
const cid = await context.ipld.put(parent, mc.DAG_PB, {
3230
cidVersion: options.cidVersion,
3331
hashAlg,
3432
onlyHash: !options.flush
@@ -184,7 +182,10 @@ const createShard = async (context, contents, options) => {
184182
flat: false,
185183
mtime: options.mtime,
186184
mode: options.mode
187-
}, options)
185+
}, {
186+
...options,
187+
codec: 'dag-pb'
188+
})
188189

189190
for (let i = 0; i < contents.length; i++) {
190191
await shard._bucket.put(contents[i].name, {

Diff for: src/core/utils/remove-link.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ const removeLink = async (context, options) => {
4848
}
4949

5050
const removeFromDirectory = async (context, options) => {
51-
const format = mc[options.format.toUpperCase().replace(/-/g, '_')]
5251
const hashAlg = mh.names[options.hashAlg]
5352

5453
options.parent.rmLink(options.name)
55-
const cid = await context.ipld.put(options.parent, format, {
54+
const cid = await context.ipld.put(options.parent, mc.DAG_PB, {
5655
cidVersion: options.cidVersion,
5756
hashAlg
5857
})
@@ -79,7 +78,6 @@ const removeFromShardedDirectory = async (context, options) => {
7978
cid: options.cid,
8079
size: options.size,
8180
hashAlg: options.hashAlg,
82-
format: options.format,
8381
cidVersion: options.cidVersion,
8482
flush: options.flush
8583
}, options)

Diff for: src/core/utils/update-tree.js

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const updateTree = async (context, trail, options) => {
3939
size: child.size,
4040
flush: options.flush,
4141
shardSplitThreshold: options.shardSplitThreshold,
42-
format: options.format,
4342
hashAlg: options.hashAlg,
4443
cidVersion: options.cidVersion
4544
})

Diff for: src/core/write.js

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const defaultOptions = {
2828
reduceSingleLeafToSelf: false,
2929
cidVersion: 0,
3030
hashAlg: 'sha2-256',
31-
format: 'dag-pb',
3231
parents: false, // whether to create intermediate directories if they do not exist
3332
progress: () => {},
3433
strategy: 'trickle',
@@ -104,7 +103,6 @@ const updateOrImport = async (context, path, source, destination, options) => {
104103
size: child.size,
105104
flush: options.flush,
106105
shardSplitThreshold: options.shardSplitThreshold,
107-
format: options.format,
108106
hashAlg: options.hashAlg,
109107
cidVersion: options.cidVersion
110108
})

0 commit comments

Comments
 (0)