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

Commit 92c85cf

Browse files
committed
Merge pull request #316 from ipfs/booyah
cat interface-core upgrades
2 parents bf62c28 + 4893773 commit 92c85cf

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"form-data": "^1.0.0-rc3",
4646
"gulp": "^3.9.1",
4747
"idb-plus-blob-store": "^1.1.2",
48-
"interface-ipfs-core": "^0.2.2",
48+
"interface-ipfs-core": "^0.3.0",
4949
"left-pad": "^1.1.0",
5050
"lodash": "^4.11.2",
5151
"mocha": "^2.5.1",
@@ -67,7 +67,7 @@
6767
"glob": "^7.0.3",
6868
"hapi": "^13.4.1",
6969
"ipfs-bitswap": "^0.4.1",
70-
"ipfs-api": "^5.0.1",
70+
"ipfs-api": "^6.0.1",
7171
"ipfs-block": "^0.3.0",
7272
"ipfs-block-service": "^0.4.0",
7373
"ipfs-merkle-dag": "^0.6.0",

src/cli/commands/files/cat.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ module.exports = Command.extend({
3131
})
3232
return
3333
}
34-
ipfs.files.cat(path, (err, res) => {
34+
ipfs.files.cat(path, (err, file) => {
3535
if (err) {
3636
throw (err)
3737
}
38-
res.on('data', (data) => {
39-
data.content.pipe(process.stdout)
40-
})
38+
file.pipe(process.stdout)
4139
})
4240
})
4341
}

src/core/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ function IPFS (repoInstance) {
5757
this.object = object(this)
5858
this.libp2p = libp2p(this)
5959
this.files = files(this)
60+
this.cat = files(this).cat // Alias for js-ipfs-api cat
6061
this.bitswap = bitswap(this)
6162
}

src/core/ipfs/files.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,26 @@ module.exports = function files (self) {
100100
i.end()
101101
}),
102102

103-
cat: (hash, callback) => {
103+
cat: promisify((hash, callback) => {
104+
if (typeof hash === 'function') {
105+
return callback(new Error('You must supply a multihash'))
106+
}
104107
self._dagS.get(hash, (err, fetchedNode) => {
105108
if (err) {
106-
return callback(err, null)
109+
return callback(err)
107110
}
108111
const data = UnixFS.unmarshal(fetchedNode.data)
109112
if (data.type === 'directory') {
110-
callback('This dag node is a directory', null)
113+
callback(new Error('This dag node is a directory'))
111114
} else {
112115
const exportStream = Exporter(hash, self._dagS)
113-
callback(null, exportStream)
116+
exportStream.once('data', (object) => {
117+
callback(null, object.content)
118+
})
114119
}
115120
})
116-
},
121+
}),
122+
117123
get: (hash, callback) => {
118124
var exportFile = Exporter(hash, self._dagS)
119125
callback(null, exportFile)

src/http-api/resources/files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ exports.cat = {
4343
}).code(500)
4444
}
4545
stream.on('data', (data) => {
46-
return reply(data.content)
46+
return reply(data)
4747
})
4848
})
4949
}

0 commit comments

Comments
 (0)