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

Follow interface-ipfs-core for files.cat #292

Merged
merged 3 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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"flatmap": "0.0.3",
"glob": "^7.0.3",
"ipfs-merkle-dag": "^0.6.0",
"is-ipfs": "^0.2.0",
"isstream": "^0.1.2",
"multiaddr": "^2.0.0",
"multipart-stream": "^2.0.1",
Expand All @@ -32,7 +33,7 @@
"aegir": "^3.2.0",
"chai": "^3.5.0",
"gulp": "^3.9.1",
"interface-ipfs-core": "^0.2.2",
"interface-ipfs-core": "^0.3.0",
"ipfsd-ctl": "^0.14.0",
"pre-commit": "^1.1.2",
"stream-equal": "^0.1.8",
Expand Down Expand Up @@ -93,4 +94,4 @@
"url": "https://github.com/ipfs/js-ipfs-api/issues"
},
"homepage": "https://github.com/ipfs/js-ipfs-api"
}
}
24 changes: 22 additions & 2 deletions src/api/cat.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
'use strict'

const argCommand = require('../cmd-helpers').argCommand
const bs58 = require('bs58')
const isIPFS = require('is-ipfs')
const promisify = require('promisify-es6')

module.exports = (send) => {
return argCommand(send, 'cat')
const cat = promisify((multihash, callback) => {
try {
multihash = cleanMultihash(multihash)
} catch (err) {
return callback(err)
}
send('cat', multihash, null, null, callback)
})
return cat
}

function cleanMultihash (multihash) {
if (!isIPFS.multihash(multihash)) {
throw new Error('not valid multihash')
}
if (Buffer.isBuffer(multihash)) {
return bs58.encode(multihash)
}
return multihash
}
16 changes: 0 additions & 16 deletions test/api/add.spec.js

This file was deleted.

77 changes: 0 additions & 77 deletions test/api/cat.spec.js

This file was deleted.

15 changes: 14 additions & 1 deletion test/api/files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@
const expect = require('chai').expect
const isNode = require('detect-node')
const path = require('path')
const test = require('interface-ipfs-core')

let testfile

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

describe('.files', () => {
// Load the add/cat/get/ls commands from interface-ipfs-core
const common = {
setup: function (cb) {
cb(null, apiClients.a)
},
teardown: function (cb) {
cb()
}
}
test.files(common)

// Describe the (mfs) tests
describe('.files (pseudo mfs)', () => {
it('files.mkdir', (done) => {
apiClients.a.files.mkdir('/test-folder', function (err) {
expect(err).to.not.exist
Expand Down