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

Commit dd64c4c

Browse files
committed
Merge pull request #292 from ipfs/interface/cat
Follow interface-ipfs-core for files.cat
2 parents 8b9ee53 + 2483ba1 commit dd64c4c

File tree

5 files changed

+39
-98
lines changed

5 files changed

+39
-98
lines changed

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"flatmap": "0.0.3",
1414
"glob": "^7.0.3",
1515
"ipfs-merkle-dag": "^0.6.0",
16+
"is-ipfs": "^0.2.0",
1617
"isstream": "^0.1.2",
1718
"multiaddr": "^2.0.0",
1819
"multipart-stream": "^2.0.1",
@@ -32,7 +33,7 @@
3233
"aegir": "^3.2.0",
3334
"chai": "^3.5.0",
3435
"gulp": "^3.9.1",
35-
"interface-ipfs-core": "^0.2.2",
36+
"interface-ipfs-core": "^0.3.0",
3637
"ipfsd-ctl": "^0.14.0",
3738
"pre-commit": "^1.1.2",
3839
"stream-equal": "^0.1.8",
@@ -93,4 +94,4 @@
9394
"url": "https://github.com/ipfs/js-ipfs-api/issues"
9495
},
9596
"homepage": "https://github.com/ipfs/js-ipfs-api"
96-
}
97+
}

src/api/cat.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
'use strict'
22

3-
const argCommand = require('../cmd-helpers').argCommand
3+
const bs58 = require('bs58')
4+
const isIPFS = require('is-ipfs')
5+
const promisify = require('promisify-es6')
46

57
module.exports = (send) => {
6-
return argCommand(send, 'cat')
8+
const cat = promisify((multihash, callback) => {
9+
try {
10+
multihash = cleanMultihash(multihash)
11+
} catch (err) {
12+
return callback(err)
13+
}
14+
send('cat', multihash, null, null, callback)
15+
})
16+
return cat
17+
}
18+
19+
function cleanMultihash (multihash) {
20+
if (!isIPFS.multihash(multihash)) {
21+
throw new Error('not valid multihash')
22+
}
23+
if (Buffer.isBuffer(multihash)) {
24+
return bs58.encode(multihash)
25+
}
26+
return multihash
727
}

test/api/add.spec.js

-16
This file was deleted.

test/api/cat.spec.js

-77
This file was deleted.

test/api/files.spec.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@
55
const expect = require('chai').expect
66
const isNode = require('detect-node')
77
const path = require('path')
8+
const test = require('interface-ipfs-core')
89

910
let testfile
1011

1112
testfile = require('fs').readFileSync(path.join(__dirname, '/../testfile.txt'))
1213

13-
describe('.files', () => {
14+
// Load the add/cat/get/ls commands from interface-ipfs-core
15+
const common = {
16+
setup: function (cb) {
17+
cb(null, apiClients.a)
18+
},
19+
teardown: function (cb) {
20+
cb()
21+
}
22+
}
23+
test.files(common)
24+
25+
// Describe the (mfs) tests
26+
describe('.files (pseudo mfs)', () => {
1427
it('files.mkdir', (done) => {
1528
apiClients.a.files.mkdir('/test-folder', function (err) {
1629
expect(err).to.not.exist

0 commit comments

Comments
 (0)