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

Commit 03b6ade

Browse files
committed
removed add test, opened up large file cat test
1 parent b9b8287 commit 03b6ade

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ A valid (read: that follows this interface) IPFS core implementation, must expos
5959

6060
### `cat`
6161

62-
> Streams the data contained by an IPFS object(s) at the given IPFS multihash..
62+
> Streams the file at the given IPFS multihash..
6363
6464
##### `Go` **WIP**
6565

test/files.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ const expect = require('chai').expect
55
const bl = require('bl')
66
const bs58 = require('bs58')
77
const Readable = require('readable-stream')
8+
const isNode = require('detect-node')
9+
const path = require('path')
10+
11+
let testfileBig
12+
13+
if (isNode) {
14+
const fs = require('fs')
15+
testfileBig = fs.readFileSync(path.join(__dirname, './test-data/15mb.random'), { bufferSize: 128 })
16+
}
817

918
module.exports = (common) => {
1019
describe('.file', () => {
@@ -22,26 +31,6 @@ module.exports = (common) => {
2231
common.teardown(done)
2332
})
2433

25-
// go-ipfs http and js-ipfs core have different responses
26-
describe('.add', () => {
27-
it('add', (done) => {
28-
const buffered = new Buffer('some data')
29-
const rs = new Readable()
30-
rs.push(buffered)
31-
rs.push(null)
32-
const arr = []
33-
const filePair = {path: 'data.txt', content: rs}
34-
arr.push(filePair)
35-
ipfs.add(arr, (err, res) => {
36-
expect(err).to.not.exist
37-
expect(res[0].path).to.equal('data.txt')
38-
expect(res[0].size).to.equal(17)
39-
expect(bs58.encode(res[0].multihash).toString()).to.equal('QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS')
40-
done()
41-
})
42-
})
43-
})
44-
4534
describe('.cat', () => {
4635
it('returns file stream', (done) => {
4736
const hash = 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'
@@ -56,7 +45,7 @@ module.exports = (common) => {
5645
})
5746

5847
// This fails on js-ipfs-api
59-
it.skip('takes a buffer input', (done) => {
48+
it('takes a buffer input', (done) => {
6049
const mhBuf = new Buffer(bs58.decode('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'))
6150
ipfs.cat(mhBuf, (err, file) => {
6251
expect(err).to.not.exist
@@ -69,12 +58,13 @@ module.exports = (common) => {
6958
})
7059

7160
// You can add a large file to your ipfs repo and change the hash to the file after installing js-ipfs
72-
it.skip('returns a large file', (done) => {
73-
const hash = ''
61+
it('returns a large file', (done) => {
62+
const hash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
7463
ipfs.cat(hash, (err, file) => {
7564
expect(err).to.not.exist
7665
file.pipe(bl((err, bldata) => {
7766
expect(err).to.not.exist
67+
expect(bldata).to.deep.equal(testfileBig)
7868
done()
7969
}))
8070
})
@@ -127,6 +117,21 @@ module.exports = (common) => {
127117
done()
128118
})
129119
})
120+
121+
it('takes a buffer input', (done) => {
122+
const hash = new Buffer(bs58.decode('QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB'))
123+
ipfs.cat(hash)
124+
.then((stream) => {
125+
stream.pipe(bl((err, bldata) => {
126+
expect(err).to.not.exist
127+
expect(bldata.toString()).to.contain('Check out some of the other files in this directory:')
128+
done()
129+
}))
130+
})
131+
.catch((err) => {
132+
expect(err).to.not.exist
133+
})
134+
})
130135
})
131136
})
132137
})

0 commit comments

Comments
 (0)