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

Commit 164ba88

Browse files
nginneverhackergrrl
authored andcommitted
cr
1 parent ada8206 commit 164ba88

File tree

2 files changed

+27
-58
lines changed

2 files changed

+27
-58
lines changed

src/api/get.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
'use strict'
22

33
module.exports = (send) => {
4-
return function get (path, archive, compress, compressionLevel, cb) {
5-
if (archive === true && typeof compress === 'function') {
6-
cb = compress
7-
compressionLevel = null
8-
compress = null
4+
return function get (path, opts, cb) {
5+
if (typeof opts === 'function' && !cb) {
6+
cb = opts
7+
opts = {}
98
}
10-
if (archive === true && typeof compress === 'number') {
11-
archive = null
12-
cb = compressionLevel
13-
compressionLevel = compress
14-
compress = true
15-
}
16-
if (typeof archive === 'function') {
17-
cb = archive
18-
archive = null
19-
compressionLevel = null
20-
compress = null
21-
}
22-
return send('get', path, [archive, compress, compressionLevel], null, cb)
9+
return send('get', path, opts, null, cb)
2310
}
2411
}

test/api/get.spec.js

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const expect = require('chai').expect
66
const isNode = require('detect-node')
77
const fs = require('fs')
8+
const bl = require('bl')
89

910
const path = require('path')
1011
const streamEqual = require('stream-equal')
@@ -24,59 +25,40 @@ describe('.get', () => {
2425
apiClients.a
2526
.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => {
2627
expect(err).to.not.exist
27-
28-
let buf = ''
29-
res
30-
.on('error', (err) => {
31-
expect(err).to.not.exist
32-
})
33-
.on('data', (data) => {
34-
buf += data
35-
})
36-
.on('end', () => {
37-
expect(buf).to.contain(testfile.toString())
38-
done()
39-
})
28+
res.pipe(bl((err, bldata) => {
29+
expect(err).to.not.exist
30+
expect(bldata.toString()).to.contain(testfile.toString())
31+
done()
32+
}))
4033
})
4134
})
4235

4336
it('get with archive true', (done) => {
4437
apiClients.a
45-
.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', true, (err, res) => {
38+
.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {archive: true}, (err, res) => {
4639
expect(err).to.not.exist
40+
res.pipe(bl((err, bldata) => {
41+
expect(err).to.not.exist
42+
expect(bldata.toString()).to.contain(testfile.toString())
43+
done()
44+
}))
45+
})
46+
})
4747

48-
let buf = ''
49-
res
50-
.on('error', (err) => {
51-
expect(err).to.not.exist
52-
})
53-
.on('data', (data) => {
54-
buf += data
55-
})
56-
.on('end', () => {
57-
expect(buf).to.contain(testfile.toString())
58-
done()
59-
})
48+
it('get err with out of range compression level', (done) => {
49+
apiClients.a
50+
.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {compress: true, 'compression-level': 10}, (err, res) => {
51+
expect(err).to.exist
52+
expect(err.toString()).to.equal('Error: Compression level must be between 1 and 9')
53+
done()
6054
})
6155
})
6256

6357
it('get with compression level', (done) => {
6458
apiClients.a
65-
.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', true, 1, (err, res) => {
59+
.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {compress: true, 'compression-level': 1}, (err, res) => {
6660
expect(err).to.not.exist
67-
68-
let buf = ''
69-
res
70-
.on('error', (err) => {
71-
expect(err).to.not.exist
72-
})
73-
.on('data', (data) => {
74-
buf += data
75-
})
76-
.on('end', () => {
77-
expect(buf).to.contain(testfile.toString())
78-
done()
79-
})
61+
done()
8062
})
8163
})
8264

0 commit comments

Comments
 (0)