This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
License: MIT Signed-off-by: Rasmus Erik Voel Jensen <github-rasmuserik@solsort.dk>
- Loading branch information
1 parent
03610b5
commit 5fc029d
Showing
4 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict' | ||
|
||
const {print, rightpad} = require('../utils') | ||
const Unixfs = require('ipfs-unixfs') | ||
|
||
module.exports = { | ||
command: 'ls <key>', | ||
|
||
describe: 'List files for the given directory', | ||
|
||
builder: { | ||
v: { | ||
alias: 'headers', | ||
desc: 'Print table headers (Hash, Size, Name).', | ||
type: 'boolean', | ||
default: false | ||
}, | ||
'resolve-type': { | ||
desc: 'Resolve linked objects to find out their types. (not implemented yet)', | ||
type: 'boolean', | ||
default: false // should be true when implemented | ||
} | ||
}, | ||
|
||
handler (argv) { | ||
let path = argv.key | ||
if (path.startsWith('/ipfs/')) { | ||
path = path.replace('/ipfs/', '') | ||
} | ||
|
||
argv.ipfs.object.get(path, {enc: 'base58'}, (err, node) => { | ||
if (err) { | ||
throw err | ||
} | ||
let {data, links} = node.toJSON() | ||
|
||
const fileDesc = Unixfs.unmarshal(data) | ||
if (fileDesc.type !== 'directory') { | ||
throw new Error('merkeldag node was not a directory') // TODO: support shards | ||
} | ||
|
||
if (argv['resolve-type']) { | ||
throw new Error('--resolve-type not implemented yet') | ||
} | ||
|
||
if (argv.headers) { | ||
links = [{multihash: 'Hash', size: 'Size', name: 'Name'}].concat(links) | ||
} | ||
|
||
const multihashWidth = Math.max.apply(null, links.map((file) => String(file.multihash).length)) | ||
const sizeWidth = Math.max.apply(null, links.map((file) => String(file.size).length)) | ||
|
||
links.forEach((file) => { | ||
print(rightpad(file.multihash, multihashWidth + 1) + | ||
rightpad(file.size, sizeWidth + 1) + | ||
file.name) | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters