Verified Commit 6ac0c156 authored by Aral Balkan's avatar Aral Balkan
Browse files

Now saving md5 hash of the latest blocker list file

Will be used to check for updates by the apps.
parent 73aec20e
......@@ -43,6 +43,16 @@ GlobalStatistics = require './GlobalStatistics'
require './StringExtensions' # for String::trim()
require 'crypto'
# Calculate checksum
checksum = (str) ->
return crypto
.update(str, 'utf8')
class Blockdown
......@@ -790,12 +800,15 @@ Better is a Safari content blocker for <a href='
saveBlockerListJSON: (dataDirectory) =>
blockerListJSONFilePath = path.join dataDirectory, 'blockerList.json'
blockerListJSONHashFilePath = path.join dataDirectory, 'blockerList.json.md5'
# In development, pretty print the JSON to make it easier to debug.
# In production, minify it for better performance.
args = if app.isRunningInDevelopment then [@rules, null, 4] else [@rules]
fs.outputFileAsync blockerListJSONFilePath, JSON.stringify.apply @, args
output = JSON.stringify.apply @, args
hash = checksum(output)
(fs.outputFileAsync blockerListJSONFilePath, JSON.stringify.apply @, args).then =>
fs.outputFileAsync blockerListJSONHashFilePath, hash
# Saves the rule partials in JSON format.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment