diff options
author | gtuk <gtuk@hush.ai> | 2014-09-07 11:57:09 +0400 |
---|---|---|
committer | gtuk <gtuk@hush.ai> | 2014-09-07 11:57:09 +0400 |
commit | e1e8cbda90011ea087b737a79989729f8a844faa (patch) | |
tree | b21fb2906552542f474c240e94c2f9664251f6bc /index.js | |
parent | f62d66375e90d81f6ec046591613b6d7cf840578 (diff) |
Add gzip support for blocklist
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 35 |
1 files changed, 27 insertions, 8 deletions
@@ -16,6 +16,8 @@ var parseTorrent = require('parse-torrent') var pump = require('pump') var rangeParser = require('range-parser') var url = require('url') +var gzip = require('zlib').Gunzip() + inherits(WebTorrent, Client) @@ -206,14 +208,31 @@ WebTorrent.prototype._onRequest = function (req, res) { } } -// TODO: support gzipped files var blocklistRe = /^\s*[^#].*?\s*:\s*([a-f0-9.:]+?)\s*-\s*([a-f0-9.:]+?)\s*$/ function parseBlocklist (filename) { - var blocklistData = fs.readFileSync(filename, 'utf8') - var blocklist = [] - blocklistData.split('\n').forEach(function (line) { - var match = blocklistRe.exec(line) - if (match) blocklist.push({ start: match[1], end: match[2] }) - }) - return blocklist + if( filename.substring(filename.lastIndexOf('.')+1) == 'gz' ) { + var input = fs.createReadStream(filename); + filename = filename.substring(0, filename.lastIndexOf('.'))+'.txt' + var output = fs.createWriteStream(filename); + + var result = input.pipe(gzip).pipe(output); + result.on('finish', function () { + var blocklistData = fs.readFileSync(filename, 'utf8') + var blocklist = [] + blocklistData.split('\n').forEach(function (line) { + var match = blocklistRe.exec(line) + if (match) blocklist.push({ start: match[1], end: match[2] }) + }) + return blocklist + }) + } + else { + var blocklistData = fs.readFileSync(filename, 'utf8') + var blocklist = [] + blocklistData.split('\n').forEach(function (line) { + var match = blocklistRe.exec(line) + if (match) blocklist.push({ start: match[1], end: match[2] }) + }) + return blocklist + } } |