diff --git a/lib/read.js b/lib/read.js index 18003b9..a8a0754 100644 --- a/lib/read.js +++ b/lib/read.js @@ -2,6 +2,7 @@ const fs = require('fs'); const BStream = require('bncode').Stream; const schema = require('./schema'); +const Torrent = require('./torrent'); /** @@ -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) => { + if (typeof validate === 'function') { + callback = validate; + validate = true + } if (!callback) { callback = () => {}; } + var rs = typeof file === 'string' ? fs.createReadStream(file) : file; var bstream = new BStream(); rs.pipe(bstream); @@ -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;