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

cat interface-core upgrades #316

Merged
merged 2 commits into from
Jun 7, 2016
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"form-data": "^1.0.0-rc3",
"gulp": "^3.9.1",
"idb-plus-blob-store": "^1.1.2",
"interface-ipfs-core": "^0.2.2",
"interface-ipfs-core": "^0.3.0",
"left-pad": "^1.1.0",
"lodash": "^4.11.2",
"mocha": "^2.5.1",
Expand All @@ -67,7 +67,7 @@
"glob": "^7.0.3",
"hapi": "^13.4.1",
"ipfs-bitswap": "^0.4.1",
"ipfs-api": "^5.0.1",
"ipfs-api": "^6.0.1",
"ipfs-block": "^0.3.0",
"ipfs-block-service": "^0.4.0",
"ipfs-merkle-dag": "^0.6.0",
Expand Down
6 changes: 2 additions & 4 deletions src/cli/commands/files/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ module.exports = Command.extend({
})
return
}
ipfs.files.cat(path, (err, res) => {
ipfs.files.cat(path, (err, file) => {
if (err) {
throw (err)
}
res.on('data', (data) => {
data.content.pipe(process.stdout)
})
file.pipe(process.stdout)
})
})
}
Expand Down
1 change: 1 addition & 0 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ function IPFS (repoInstance) {
this.object = object(this)
this.libp2p = libp2p(this)
this.files = files(this)
this.cat = files(this).cat // Alias for js-ipfs-api cat
this.bitswap = bitswap(this)
}
16 changes: 11 additions & 5 deletions src/core/ipfs/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,26 @@ module.exports = function files (self) {
i.end()
}),

cat: (hash, callback) => {
cat: promisify((hash, callback) => {
if (typeof hash === 'function') {
return callback(new Error('You must supply a multihash'))
}
self._dagS.get(hash, (err, fetchedNode) => {
if (err) {
return callback(err, null)
return callback(err)
}
const data = UnixFS.unmarshal(fetchedNode.data)
if (data.type === 'directory') {
callback('This dag node is a directory', null)
callback(new Error('This dag node is a directory'))
} else {
const exportStream = Exporter(hash, self._dagS)
callback(null, exportStream)
exportStream.once('data', (object) => {
callback(null, object.content)
})
}
})
},
}),

get: (hash, callback) => {
var exportFile = Exporter(hash, self._dagS)
callback(null, exportFile)
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/resources/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ exports.cat = {
}).code(500)
}
stream.on('data', (data) => {
return reply(data.content)
return reply(data)
})
})
}
Expand Down