Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit a82a5dc

Browse files
author
Alan Shaw
authored
refactor: files API (#1720)
BREAKING CHANGE: Files API methods `add*`, `cat*`, `get*` have moved from `files` to the root namespace. Specifically, the following changes have been made: * `ipfs.files.add` => `ipfs.add` * `ipfs.files.addPullStream` => `ipfs.addPullStream` * `ipfs.files.addReadableStream` => `ipfs.addReadableStream` * `ipfs.files.cat` => `ipfs.cat` * `ipfs.files.catPullStream` => `ipfs.catPullStream` * `ipfs.files.catReadableStream` => `ipfs.catReadableStream` * `ipfs.files.get` => `ipfs.get` * `ipfs.files.getPullStream` => `ipfs.getPullStream` * `ipfs.files.getReadableStream` => `ipfs.getReadableStream` License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent b6b50d5 commit a82a5dc

Some content is hidden

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

48 files changed

+858
-576
lines changed

README.md

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
<br>
2626
</p>
2727

28-
### Project status
28+
### Project status - `Alpha`
2929

3030
We've come a long way, but this project is still in Alpha, lots of development is happening, API might change, beware of the Dragons 🐉..
3131

3232
**Want to get started?** Check our [examples folder](/examples) to learn how to spawn an IPFS node in Node.js and in the Browser.
3333

34-
You can check the development status at the [Waffle Board](https://waffle.io/ipfs/js-ipfs).
34+
You can check the development status at the [Kanban Board](https://waffle.io/ipfs/js-ipfs).
3535

3636
[![Throughput Graph](https://graphs.waffle.io/ipfs/js-ipfs/throughput.svg)](https://waffle.io/ipfs/js-ipfs/metrics/throughput)
3737

@@ -494,36 +494,35 @@ The core API is grouped into several areas:
494494

495495
#### Files
496496

497-
- [files](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md)
498-
- [`ipfs.files.add(data, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesadd).
499-
- [`ipfs.files.addPullStream([options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesaddpullstream)
500-
- [`ipfs.files.addReadableStream([options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesaddreadablestream)
501-
- [`ipfs.files.cat(ipfsPath, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filescat).
502-
- [`ipfs.files.catPullStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filescatpullstream)
503-
- [`ipfs.files.catReadableStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filescatreadablestream)
504-
- [`ipfs.files.get(ipfsPath, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesget).
505-
- [`ipfs.files.getPullStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesgetpullstream)
506-
- [`ipfs.files.getReadableStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesgetreadablestream)
497+
- [Regular Files API](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md)
498+
- [`ipfs.add(data, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#add)
499+
- [`ipfs.addPullStream([options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addpullstream)
500+
- [`ipfs.addReadableStream([options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addreadablestream)
501+
- [`ipfs.addFromStream(stream, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addfromstream)
502+
- [`ipfs.addFromFs(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addfromfs)
503+
- [`ipfs.addFromUrl(url, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#addfromurl)
504+
- [`ipfs.cat(ipfsPath, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#cat)
505+
- [`ipfs.catPullStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#catpullstream)
506+
- [`ipfs.catReadableStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#catreadablestream)
507+
- [`ipfs.get(ipfsPath, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#get)
508+
- [`ipfs.getPullStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#getpullstream)
509+
- [`ipfs.getReadableStream(ipfsPath, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#getreadablestream)
507510
- [`ipfs.ls(ipfsPath, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#ls)
508511
- [`ipfs.lsPullStream(ipfsPath)`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#lspullstream)
509512
- [`ipfs.lsReadableStream(ipfsPath)`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#lsreadablestream)
510-
- [MFS (mutable file system) specific](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#mutable-file-system)
511-
- [`ipfs.files.cp([from, to], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filescp)
512-
- [`ipfs.files.flush([path], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesflush)
513-
- [`ipfs.files.ls([path], [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesls)
514-
- [`ipfs.files.mkdir(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesmkdir)
515-
- [`ipfs.files.mv([from, to], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesmv)
516-
- [`ipfs.files.read(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesread)
517-
- [`ipfs.files.readPullStream(path, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesreadpullstream)
518-
- [`ipfs.files.readReadableStream(path, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesreadreadablestream)
519-
- [`ipfs.files.rm(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesrm)
520-
- [`ipfs.files.stat(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesstat)
521-
- [`ipfs.files.write(path, content, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#fileswrite)
513+
- [MFS (mutable file system) specific](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#mutable-file-system)
514+
- [`ipfs.files.cp([from, to], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filescp)
515+
- [`ipfs.files.flush([path], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesflush)
516+
- [`ipfs.files.ls([path], [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesls)
517+
- [`ipfs.files.mkdir(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesmkdir)
518+
- [`ipfs.files.mv([from, to], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesmv)
519+
- [`ipfs.files.read(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesread)
520+
- [`ipfs.files.readPullStream(path, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesreadpullstream)
521+
- [`ipfs.files.readReadableStream(path, [options])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesreadreadablestream)
522+
- [`ipfs.files.rm(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesrm)
523+
- [`ipfs.files.stat(path, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#filesstat)
524+
- [`ipfs.files.write(path, content, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/FILES.md#fileswrite)
522525

523-
- [block](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md)
524-
- [`ipfs.block.get(cid, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md#blockget)
525-
- [`ipfs.block.put(block, cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md#blockput)
526-
- [`ipfs.block.stat(cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md#blockstat)
527526

528527
#### Graph
529528

@@ -532,7 +531,12 @@ The core API is grouped into several areas:
532531
- [`ipfs.dag.get(cid, [path], [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/DAG.md#dagget)
533532
- [`ipfs.dag.tree(cid, [path], [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/DAG.md#dagtree)
534533

535-
- [object](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/OBJECT.md)
534+
- [pin](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/PIN.md)
535+
- [`ipfs.pin.add(hash, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/PIN.md#pinadd)
536+
- [`ipfs.pin.ls([hash], [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/PIN.md#pinls)
537+
- [`ipfs.pin.rm(hash, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/PIN.md#pinrm)
538+
539+
- [object (legacy)](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/OBJECT.md)
536540
- [`ipfs.object.new([template], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/OBJECT.md#objectnew)
537541
- [`ipfs.object.put(obj, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/OBJECT.md#objectput)
538542
- [`ipfs.object.get(multihash, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/OBJECT.md#objectget)
@@ -544,10 +548,15 @@ The core API is grouped into several areas:
544548
- [`ipfs.object.patch.appendData(multihash, data, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/OBJECT.md#objectpatchappenddata)
545549
- [`ipfs.object.patch.setData(multihash, data, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/OBJECT.md#objectpatchsetdata)
546550

547-
- [pin](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/PIN.md)
548-
- [`ipfs.pin.add(hash, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/PIN.md#pinadd)
549-
- [`ipfs.pin.ls([hash], [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/PIN.md#pinls)
550-
- [`ipfs.pin.rm(hash, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/PIN.md#pinrm)
551+
#### Block
552+
553+
- [block](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md)
554+
- [`ipfs.block.get(cid, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md#blockget)
555+
- [`ipfs.block.put(block, cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md#blockput)
556+
- [`ipfs.block.stat(cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BLOCK.md#blockstat)
557+
- [bitswap](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BITSWAP.md)
558+
- [`ipfs.bitswap.wantlist([peerId], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BITSWAP.md#bitswapwantlist)
559+
- [`ipfs.bitswap.stat([callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BITSWAP.md#bitswapstat)
551560

552561
#### Name
553562

@@ -574,10 +583,6 @@ The core API is grouped into several areas:
574583
- [`ipfs.bootstrap.add(addr, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BOOTSTRAP.md#bootstrapadd)
575584
- [`ipfs.bootstrap.rm(peer, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BOOTSTRAP.md#bootstraprm)
576585

577-
- [bitswap](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/BITSWAP.md)
578-
- [`ipfs.bitswap.wantlist([peerId], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BITSWAP.md#bitswapwantlist)
579-
- [`ipfs.bitswap.stat([callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BITSWAP.md#bitswapstat)
580-
581586
- dht (not implemented yet)
582587

583588
- [pubsub](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md)
@@ -1007,10 +1012,10 @@ What does this image explain?
10071012

10081013
IPFS implementation in JavaScript is a work in progress. As such, there's a few things you can do right now to help out:
10091014
1010-
* Go through the modules below and **check out existing issues**. This would be especially useful for modules in active development. Some knowledge of IPFS may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
1011-
* **Perform code reviews**. More eyes will help (a) speed the project along, (b) ensure quality, and (c) reduce possible future bugs.
1012-
* Take a look at go-ipfs and some of the planning repositories or issues: for instance, the [libp2p spec](https://github.com/ipfs/specs/pull/19). Contributions here that would be most helpful are **top-level comments** about how it should look based on our understanding. Again, the more eyes the better.
1013-
* **Add tests**. There can never be enough tests.
1015+
- Go through the modules below and **check out existing issues**. This would be especially useful for modules in active development. Some knowledge of IPFS may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
1016+
- **Perform code reviews**. More eyes will help (a) speed the project along, (b) ensure quality, and (c) reduce possible future bugs.
1017+
- Take a look at go-ipfs and some of the planning repositories or issues: for instance, the [libp2p spec](https://github.com/ipfs/specs/pull/19). Contributions here that would be most helpful are **top-level comments** about how it should look based on our understanding. Again, the more eyes the better.
1018+
- **Add tests**. There can never be enough tests.
10141019
10151020
### Want to hack on IPFS?
10161021

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
"execa": "^1.0.0",
7070
"form-data": "^2.3.3",
7171
"hat": "0.0.3",
72-
"interface-ipfs-core": "~0.84.2",
73-
"ipfsd-ctl": "~0.39.5",
72+
"interface-ipfs-core": "~0.86.0",
73+
"ipfsd-ctl": "ipfs/js-ipfsd-ctl#update-dag-pb-to-not-have-cid-property",
7474
"ncp": "^2.0.0",
7575
"qs": "^6.5.2",
7676
"rimraf": "^2.6.2",
@@ -102,19 +102,19 @@
102102
"hoek": "^5.0.4",
103103
"human-to-milliseconds": "^1.0.0",
104104
"interface-datastore": "~0.6.0",
105-
"ipfs-api": "^26.1.0",
105+
"ipfs-api": "ipfs/js-ipfs-api",
106106
"ipfs-bitswap": "~0.21.0",
107107
"ipfs-block": "~0.8.0",
108108
"ipfs-block-service": "~0.15.1",
109-
"ipfs-http-response": "~0.2.0",
110-
"ipfs-mfs": "~0.4.2",
109+
"ipfs-http-response": "~0.2.1",
110+
"ipfs-mfs": "~0.5.2",
111111
"ipfs-multipart": "~0.1.0",
112-
"ipfs-repo": "~0.25.0",
112+
"ipfs-repo": "0.25.0",
113113
"ipfs-unixfs": "~0.1.16",
114-
"ipfs-unixfs-engine": "~0.33.0",
115-
"ipld": "~0.19.3",
114+
"ipfs-unixfs-engine": "~0.34.0",
115+
"ipld": "~0.20.1",
116116
"ipld-bitcoin": "~0.1.8",
117-
"ipld-dag-pb": "~0.14.11",
117+
"ipld-dag-pb": "~0.15.0",
118118
"ipld-ethereum": "^2.0.1",
119119
"ipld-git": "~0.2.2",
120120
"ipld-zcash": "~0.1.6",

src/cli/bin.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,9 @@ if (args[0] === 'daemon' || args[0] === 'init') {
6969
throw err
7070
}
7171

72-
// add mfs commands
72+
// add MFS (Files API) commands
7373
mfs(cli)
7474

75-
// NOTE: This creates an alias of
76-
// `jsipfs files {add, get, cat}` to `jsipfs {add, get, cat}`.
77-
// This will stay until https://github.com/ipfs/specs/issues/98 is resolved.
78-
const addCmd = require('./commands/files/add')
79-
const catCmd = require('./commands/files/cat')
80-
const getCmd = require('./commands/files/get')
81-
const aliases = [addCmd, catCmd, getCmd]
82-
aliases.forEach((alias) => {
83-
cli.command(alias)
84-
})
85-
8675
cli
8776
.commandDir('commands')
8877
.help()

src/cli/commands/files/add.js renamed to src/cli/commands/add.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const getFolderSize = require('get-folder-size')
1111
const byteman = require('byteman')
1212
const waterfall = require('async/waterfall')
1313
const mh = require('multihashes')
14-
const utils = require('../../utils')
15-
const print = require('../../utils').print
16-
const createProgressBar = require('../../utils').createProgressBar
14+
const utils = require('../utils')
15+
const print = require('../utils').print
16+
const createProgressBar = require('../utils').createProgressBar
1717

1818
function checkPath (inPath, recursive) {
1919
// This function is to check for the following possible inputs
@@ -231,7 +231,7 @@ module.exports = {
231231
}
232232
}
233233

234-
next(null, ipfs.files.addPullStream(options))
234+
next(null, ipfs.addPullStream(options))
235235
}
236236
], (err, addStream) => {
237237
if (err) throw err

src/cli/commands/files/cat.js renamed to src/cli/commands/cat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
length: argv.length
3030
}
3131

32-
const stream = argv.ipfs.files.catReadableStream(path, options)
32+
const stream = argv.ipfs.catReadableStream(path, options)
3333

3434
stream.once('error', (err) => {
3535
throw err

src/cli/commands/files/get.js renamed to src/cli/commands/get.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('path')
55
const mkdirp = require('mkdirp')
66
const pull = require('pull-stream')
77
const toPull = require('stream-to-pull-stream')
8-
const print = require('../../utils').print
8+
const print = require('../utils').print
99

1010
function checkArgs (hash, outPath) {
1111
// format the output directory
@@ -63,7 +63,7 @@ module.exports = {
6363

6464
const dir = checkArgs(ipfsPath, argv.output)
6565

66-
const stream = argv.ipfs.files.getReadableStream(ipfsPath)
66+
const stream = argv.ipfs.getReadableStream(ipfsPath)
6767

6868
stream.once('error', (err) => {
6969
if (err) { throw err }

src/cli/commands/object/get.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
'use strict'
22

33
const print = require('../../utils').print
4+
const {
5+
util: {
6+
cid
7+
}
8+
} = require('ipld-dag-pb')
49

510
module.exports = {
611
command: 'get <key>',
@@ -11,6 +16,10 @@ module.exports = {
1116
'data-encoding': {
1217
type: 'string',
1318
default: 'base64'
19+
},
20+
'cid-base': {
21+
default: 'base58btc',
22+
describe: 'CID base to use.'
1423
}
1524
},
1625

@@ -19,26 +28,33 @@ module.exports = {
1928
if (err) {
2029
throw err
2130
}
22-
const nodeJSON = node.toJSON()
23-
24-
if (Buffer.isBuffer(node.data)) {
25-
nodeJSON.data = node.data.toString(argv['data-encoding'] || undefined)
26-
}
27-
28-
const answer = {
29-
Data: nodeJSON.data,
30-
Hash: nodeJSON.multihash,
31-
Size: nodeJSON.size,
32-
Links: nodeJSON.links.map((l) => {
33-
return {
34-
Name: l.name,
35-
Size: l.size,
36-
Hash: l.multihash
37-
}
38-
})
39-
}
4031

41-
print(JSON.stringify(answer))
32+
cid(node, (err, result) => {
33+
if (err) {
34+
throw err
35+
}
36+
37+
let data = node.data
38+
39+
if (Buffer.isBuffer(data)) {
40+
data = node.data.toString(argv.dataEncoding || undefined)
41+
}
42+
43+
const answer = {
44+
Data: data,
45+
Hash: result.toBaseEncodedString(argv.cidBase),
46+
Size: node.size,
47+
Links: node.links.map((l) => {
48+
return {
49+
Name: l.name,
50+
Size: l.size,
51+
Hash: l.cid.toBaseEncodedString(argv.cidBase)
52+
}
53+
})
54+
}
55+
56+
print(JSON.stringify(answer))
57+
})
4258
})
4359
}
4460
}

src/cli/commands/object/links.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ module.exports = {
77

88
describe: 'Outputs the links pointed to by the specified object',
99

10-
builder: {},
10+
builder: {
11+
'cid-base': {
12+
default: 'base58btc',
13+
describe: 'CID base to use.'
14+
}
15+
},
1116

1217
handler (argv) {
1318
argv.ipfs.object.links(argv.key, {
@@ -18,9 +23,7 @@ module.exports = {
1823
}
1924

2025
links.forEach((link) => {
21-
link = link.toJSON()
22-
23-
print(`${link.multihash} ${link.size} ${link.name}`)
26+
print(`${link.cid.toBaseEncodedString(argv.cidBase)} ${link.size} ${link.name}`)
2427
})
2528
})
2629
}

src/cli/commands/object/new.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,37 @@ const debug = require('debug')
44
const log = debug('cli:object')
55
log.error = debug('cli:object:error')
66
const print = require('../../utils').print
7+
const {
8+
util: {
9+
cid
10+
}
11+
} = require('ipld-dag-pb')
712

813
module.exports = {
914
command: 'new [<template>]',
1015

1116
describe: 'Create new ipfs objects',
1217

13-
builder: {},
18+
builder: {
19+
'cid-base': {
20+
default: 'base58btc',
21+
describe: 'CID base to use.'
22+
}
23+
},
1424

1525
handler (argv) {
1626
argv.ipfs.object.new(argv.template, (err, node) => {
1727
if (err) {
1828
throw err
1929
}
2030

21-
const nodeJSON = node.toJSON()
31+
cid(node, (err, cid) => {
32+
if (err) {
33+
throw err
34+
}
2235

23-
print(nodeJSON.multihash)
36+
print(cid.toBaseEncodedString(argv.cidBase))
37+
})
2438
})
2539
}
2640
}

0 commit comments

Comments
 (0)