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 gzip support for blocklist #83

Merged
merged 1 commit into from Sep 7, 2014
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.