Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgtuk <gtuk@hush.ai>2014-09-07 11:57:09 +0400
committergtuk <gtuk@hush.ai>2014-09-07 11:57:09 +0400
commite1e8cbda90011ea087b737a79989729f8a844faa (patch)
treeb21fb2906552542f474c240e94c2f9664251f6bc /index.js
parentf62d66375e90d81f6ec046591613b6d7cf840578 (diff)
Add gzip support for blocklist
Diffstat (limited to 'index.js')
-rw-r--r--index.js35
1 files changed, 27 insertions, 8 deletions
diff --git a/index.js b/index.js
index 078c2c8..23aca16 100644
--- a/index.js
+++ b/index.js
@@ -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
+ }
}