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

fix: remove format and/or codec options #69

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"ipfs-multipart": "^0.3.0",
"ipfs-unixfs": "^0.3.0",
"ipfs-unixfs-exporter": "^0.40.0",
"ipfs-unixfs-importer": "^0.43.0",
"ipfs-unixfs-importer": "^0.43.1",
"ipfs-utils": "^0.4.2",
"ipld-dag-pb": "^0.18.0",
"it-last": "^1.0.1",
Expand Down
8 changes: 0 additions & 8 deletions src/cli/chmod.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ module.exports = {
coerce: asBoolean,
describe: 'Whether to change modes recursively'
},
codec: {
alias: 'c',
type: 'string',
default: 'dag-pb',
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
},
'hash-alg': {
alias: 'h',
type: 'string',
Expand All @@ -59,7 +53,6 @@ module.exports = {
mode,
getIpfs,
recursive,
codec,
hashAlg,
flush,
shardSplitThreshold
Expand All @@ -70,7 +63,6 @@ module.exports = {

return ipfs.files.chmod(path, mode, {
recursive,
format: codec,
hashAlg,
flush,
shardSplitThreshold
Expand Down
8 changes: 0 additions & 8 deletions src/cli/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ module.exports = {
coerce: asBoolean,
describe: 'Create any non-existent intermediate directories'
},
codec: {
alias: 'c',
type: 'string',
default: 'dag-pb',
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
},
'hash-alg': {
alias: 'h',
type: 'string',
Expand All @@ -49,7 +43,6 @@ module.exports = {
dest,
getIpfs,
parents,
codec,
flush,
hashAlg,
shardSplitThreshold
Expand All @@ -59,7 +52,6 @@ module.exports = {
const ipfs = await getIpfs()
return ipfs.files.cp(source, dest, {
parents,
format: codec,
flush,
hashAlg,
shardSplitThreshold
Expand Down
8 changes: 0 additions & 8 deletions src/cli/mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ module.exports = {
default: 0,
describe: 'Cid version to use. (experimental).'
},
codec: {
alias: 'c',
type: 'string',
default: 'dag-pb',
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
},
'hash-alg': {
alias: 'h',
type: 'string',
Expand Down Expand Up @@ -67,7 +61,6 @@ module.exports = {
getIpfs,
parents,
cidVersion,
codec,
hashAlg,
flush,
shardSplitThreshold,
Expand All @@ -81,7 +74,6 @@ module.exports = {
return ipfs.files.mkdir(path, {
parents,
cidVersion,
format: codec,
hashAlg,
flush,
shardSplitThreshold,
Expand Down
8 changes: 0 additions & 8 deletions src/cli/mv.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ module.exports = {
default: 0,
describe: 'Cid version to use. (experimental).'
},
codec: {
alias: 'c',
type: 'string',
default: 'dag-pb',
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
},
'hash-alg': {
alias: 'h',
type: 'string',
Expand Down Expand Up @@ -64,7 +58,6 @@ module.exports = {
parents,
recursive,
cidVersion,
codec,
hashAlg,
flush,
shardSplitThreshold
Expand All @@ -77,7 +70,6 @@ module.exports = {
parents,
recursive,
cidVersion,
format: codec,
hashAlg,
flush,
shardSplitThreshold
Expand Down
8 changes: 0 additions & 8 deletions src/cli/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ module.exports = {
default: 0,
describe: 'Cid version to use. (experimental).'
},
codec: {
alias: 'c',
type: 'string',
default: 'dag-pb',
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
},
'hash-alg': {
alias: 'h',
type: 'string',
Expand All @@ -56,7 +50,6 @@ module.exports = {
getIpfs,
flush,
cidVersion,
codec,
hashAlg,
shardSplitThreshold,
mtime
Expand All @@ -69,7 +62,6 @@ module.exports = {
mtime,
flush,
cidVersion,
format: codec,
hashAlg,
shardSplitThreshold
})
Expand Down
7 changes: 0 additions & 7 deletions src/cli/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ module.exports = {
type: 'string',
default: 'sha2-256'
},
codec: {
alias: ['c'],
type: 'string',
default: 'dag-pb'
},
'shard-split-threshold': {
type: 'number',
default: 1000,
Expand Down Expand Up @@ -114,7 +109,6 @@ module.exports = {
reduceSingleLeafToSelf,
cidVersion,
hashAlg,
codec,
parents,
progress,
strategy,
Expand All @@ -136,7 +130,6 @@ module.exports = {
reduceSingleLeafToSelf,
cidVersion,
hashAlg,
format: codec,
parents,
progress,
strategy,
Expand Down
6 changes: 2 additions & 4 deletions src/core/chmod.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const mh = require('multihashes')
const defaultOptions = {
flush: true,
shardSplitThreshold: 1000,
format: 'dag-pb',
hashAlg: 'sha2-256',
cidVersion: 0,
recursive: false
Expand Down Expand Up @@ -174,7 +173,7 @@ module.exports = (context) => {

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

Expand All @@ -188,8 +187,7 @@ module.exports = (context) => {
cid: updatedCid,
size: node.serialize().length,
flush: options.flush,
format: 'dag-pb',
hashAlg: 'sha2-256',
hashAlg: options.hashAlg,
cidVersion: cid.version
})

Expand Down
2 changes: 0 additions & 2 deletions src/core/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const toTrail = require('./utils/to-trail')
const defaultOptions = {
parents: false,
flush: true,
format: 'dag-pb',
hashAlg: 'sha2-256',
cidVersion: 0,
shardSplitThreshold: 1000
Expand Down Expand Up @@ -150,7 +149,6 @@ const addSourceToParent = async (context, source, childName, parent, options) =>
size: sourceBlock.data.length,
cid: source.cid,
name: childName,
format: options.format,
hashAlg: options.hashAlg,
cidVersion: options.cidVersion,
flush: options.flush
Expand Down
2 changes: 0 additions & 2 deletions src/core/mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const defaultOptions = {
hashAlg: 'sha2-256',
cidVersion: 0,
shardSplitThreshold: 1000,
format: 'dag-pb',
flush: true,
mode: null,
mtime: null
Expand Down Expand Up @@ -116,7 +115,6 @@ const addEmptyDir = async (context, childName, emptyDir, parent, trail, options)
size: emptyDir.node.size,
cid: emptyDir.cid,
name: childName,
format: options.format,
hashAlg: options.hashAlg,
cidVersion: options.cidVersion,
mode: options.mode,
Expand Down
1 change: 0 additions & 1 deletion src/core/mv.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const defaultOptions = {
recursive: false,
flush: true,
cidVersion: 0,
format: 'dag-pb',
hashAlg: 'sha2-256',
shardSplitThreshold: 1000
}
Expand Down
2 changes: 0 additions & 2 deletions src/core/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const defaultOptions = {
recursive: false,
cidVersion: 0,
hashAlg: 'sha2-256',
format: 'dag-pb',
flush: true
}

Expand Down Expand Up @@ -64,7 +63,6 @@ const removePath = async (context, path, options) => {
} = await removeLink(context, {
parentCid: parent.cid,
name: child.name,
format: options.format,
hashAlg: options.hashAlg,
cidVersion: options.cidVersion,
flush: options.flush
Expand Down
2 changes: 0 additions & 2 deletions src/core/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const defaultOptions = {
flush: true,
shardSplitThreshold: 1000,
cidVersion: 0,
format: 'dag-pb',
hashAlg: 'sha2-256'
}

Expand Down Expand Up @@ -85,7 +84,6 @@ module.exports = (context) => {
size: node.serialize().length,
flush: options.flush,
shardSplitThreshold: options.shardSplitThreshold,
format: 'dag-pb',
hashAlg: 'sha2-256',
cidVersion
})
Expand Down
3 changes: 1 addition & 2 deletions src/core/utils/add-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ const addToDirectory = async (context, options) => {
node.mtime = new Date()
options.parent = new DAGNode(node.marshal(), options.parent.Links)

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

// Persist the new parent DAGNode
const cid = await context.ipld.put(options.parent, format, {
const cid = await context.ipld.put(options.parent, mc.DAG_PB, {
cidVersion: options.cidVersion,
hashAlg,
onlyHash: !options.flush
Expand Down
7 changes: 0 additions & 7 deletions src/core/utils/apply-default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ module.exports = (options = {}, defaults) => {
}
}

const format = output.format || output.codec

if (format && isNaN(format)) {
output.format = format
delete output.codec
}

// support legacy go arguments
if (options.count !== undefined) {
output.length = options.count
Expand Down
3 changes: 1 addition & 2 deletions src/core/utils/create-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const mc = require('multicodec')
const mh = require('multihashes')

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

const node = new DAGNode(metadata.marshal())
const cid = await context.ipld.put(node, format, {
const cid = await context.ipld.put(node, mc.DAG_PB, {
cidVersion: options.cidVersion,
hashAlg,
onlyHash: !options.flush
Expand Down
9 changes: 5 additions & 4 deletions src/core/utils/hamt-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ const updateHamtDirectory = async (context, links, bucket, options) => {
mtime: node.mtime
})

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

const parent = new DAGNode(dir.marshal(), links)
const cid = await context.ipld.put(parent, format, {
const cid = await context.ipld.put(parent, mc.DAG_PB, {
cidVersion: options.cidVersion,
hashAlg,
onlyHash: !options.flush
Expand Down Expand Up @@ -184,7 +182,10 @@ const createShard = async (context, contents, options) => {
flat: false,
mtime: options.mtime,
mode: options.mode
}, options)
}, {
...options,
codec: 'dag-pb'
})

for (let i = 0; i < contents.length; i++) {
await shard._bucket.put(contents[i].name, {
Expand Down
4 changes: 1 addition & 3 deletions src/core/utils/remove-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ const removeLink = async (context, options) => {
}

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

options.parent.rmLink(options.name)
const cid = await context.ipld.put(options.parent, format, {
const cid = await context.ipld.put(options.parent, mc.DAG_PB, {
cidVersion: options.cidVersion,
hashAlg
})
Expand All @@ -79,7 +78,6 @@ const removeFromShardedDirectory = async (context, options) => {
cid: options.cid,
size: options.size,
hashAlg: options.hashAlg,
format: options.format,
cidVersion: options.cidVersion,
flush: options.flush
}, options)
Expand Down
1 change: 0 additions & 1 deletion src/core/utils/update-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const updateTree = async (context, trail, options) => {
size: child.size,
flush: options.flush,
shardSplitThreshold: options.shardSplitThreshold,
format: options.format,
hashAlg: options.hashAlg,
cidVersion: options.cidVersion
})
Expand Down
2 changes: 0 additions & 2 deletions src/core/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const defaultOptions = {
reduceSingleLeafToSelf: false,
cidVersion: 0,
hashAlg: 'sha2-256',
format: 'dag-pb',
parents: false, // whether to create intermediate directories if they do not exist
progress: () => {},
strategy: 'trickle',
Expand Down Expand Up @@ -104,7 +103,6 @@ const updateOrImport = async (context, path, source, destination, options) => {
size: child.size,
flush: options.flush,
shardSplitThreshold: options.shardSplitThreshold,
format: options.format,
hashAlg: options.hashAlg,
cidVersion: options.cidVersion
})
Expand Down
Loading