Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional parameter to skip schema validate #38

Merged
merged 5 commits into from
Jul 21, 2019
Merged
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
15 changes: 13 additions & 2 deletions lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const BStream = require('bncode').Stream;

const schema = require('./schema');
const Torrent = require('./torrent');


/**
Expand All @@ -10,12 +11,18 @@ const schema = require('./schema');
* @param {String|ReadableStream} file File where the torrent
* resides, can be local file, remote, or a readable stream.
* @param {Function(!Error, Torrent)} callback
* @param {Boolean} validate validate or not schema
* @param {ReadableStream}
*/
module.exports = (file, callback) => {
module.exports = (file, validate = true, callback) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to have the = true part here since this optional param is checked below

Suggested change
module.exports = (file, validate = true, callback) => {
module.exports = (file, validate, callback) => {

if (typeof validate === 'function') {
callback = validate;
validate = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add semicolon

Suggested change
validate = true
validate = true;

}
if (!callback) {
callback = () => {};
}

var rs = typeof file === 'string' ? fs.createReadStream(file) : file;
var bstream = new BStream();
rs.pipe(bstream);
Expand All @@ -28,7 +35,11 @@ module.exports = (file, callback) => {
});

bstream.on('data', (result) => {
schema.validate(result, callback);
if (validate) {
schema.validate(result, callback);
return;
}
callback(null, new Torrent(result));
});

return rs;
Expand Down