This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
Closed
files.get #271
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
|
||
module.exports = (send) => { | ||
return function get (path, archive, compress, compressionLevel, cb) { | ||
if (archive === true && typeof compress === 'function') { | ||
cb = compress | ||
compressionLevel = null | ||
compress = null | ||
} | ||
if (archive === true && typeof compress === 'number') { | ||
archive = null | ||
cb = compressionLevel | ||
compressionLevel = compress | ||
compress = true | ||
} | ||
if (typeof archive === 'function') { | ||
cb = archive | ||
archive = null | ||
compressionLevel = null | ||
compress = null | ||
} | ||
return send('get', path, [archive, compress, compressionLevel], null, cb) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, aren't the opts a object and not an array? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* eslint-env mocha */ | ||
/* globals apiClients */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
const isNode = require('detect-node') | ||
const fs = require('fs') | ||
|
||
const path = require('path') | ||
const streamEqual = require('stream-equal') | ||
|
||
let testfile | ||
let testfileBig | ||
|
||
if (isNode) { | ||
testfile = fs.readFileSync(path.join(__dirname, '/../testfile.txt')) | ||
testfileBig = fs.createReadStream(path.join(__dirname, '/../15mb.random'), { bufferSize: 128 }) | ||
} else { | ||
testfile = require('raw!../testfile.txt') | ||
} | ||
|
||
describe('.get', () => { | ||
it('get with no compression args', (done) => { | ||
apiClients.a | ||
.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { | ||
expect(err).to.not.exist | ||
|
||
let buf = '' | ||
res | ||
.on('error', (err) => { | ||
expect(err).to.not.exist | ||
}) | ||
.on('data', (data) => { | ||
buf += data | ||
}) | ||
.on('end', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use |
||
expect(buf).to.contain(testfile.toString()) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('get with archive true', (done) => { | ||
apiClients.a | ||
.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', true, (err, res) => { | ||
expect(err).to.not.exist | ||
|
||
let buf = '' | ||
res | ||
.on('error', (err) => { | ||
expect(err).to.not.exist | ||
}) | ||
.on('data', (data) => { | ||
buf += data | ||
}) | ||
.on('end', () => { | ||
expect(buf).to.contain(testfile.toString()) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('get with compression level', (done) => { | ||
apiClients.a | ||
.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', true, 1, (err, res) => { | ||
expect(err).to.not.exist | ||
|
||
let buf = '' | ||
res | ||
.on('error', (err) => { | ||
expect(err).to.not.exist | ||
}) | ||
.on('data', (data) => { | ||
buf += data | ||
}) | ||
.on('end', () => { | ||
expect(buf).to.contain(testfile.toString()) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it.skip('get BIG file', (done) => { | ||
if (!isNode) { | ||
return done() | ||
} | ||
|
||
apiClients.a.get('Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', (err, res) => { | ||
expect(err).to.not.exist | ||
|
||
// Do not blow out the memory of nodejs :) | ||
streamEqual(res, testfileBig, (err, equal) => { | ||
expect(err).to.not.exist | ||
expect(equal).to.be.true | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('promise', () => { | ||
it.skip('get', (done) => { | ||
return apiClients.a.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') | ||
.then((res) => { | ||
let buf = '' | ||
res | ||
.on('error', (err) => { | ||
throw err | ||
}) | ||
.on('data', (data) => { | ||
buf += data | ||
}) | ||
.on('end', () => { | ||
expect(buf).to.contain(testfile.toString()) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a switch statement instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or since
archive
,compress
,compressionLevel
are all optional, why not pass them on theopts
object?I think that you can just return the
argCommand
and it will take care of that :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, please make
archive
,compress
andcompressionLevel
into an options object.