From b503d59c49da148346aa9893d7287b8e9ccb46d2 Mon Sep 17 00:00:00 2001
From: shortcutme <tamas@zeronet.io>
Date: Wed, 9 Aug 2017 14:19:39 +0200
Subject: [PATCH] Support gzip compressed database files

---
 src/Db/Db.py            | 8 ++++++--
 src/Site/SiteStorage.py | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/Db/Db.py b/src/Db/Db.py
index c2de5509..e4939508 100644
--- a/src/Db/Db.py
+++ b/src/Db/Db.py
@@ -9,6 +9,7 @@ import gevent
 from DbCursor import DbCursor
 from Config import config
 from util import SafeRe
+from util import helper
 
 opened_dbs = []
 
@@ -244,12 +245,15 @@ class Db(object):
         # Load the json file
         try:
             if file is None:  # Open file is not file object passed
-                file = open(file_path)
+                file = open(file_path, "rb")
 
             if file is False:  # File deleted
                 data = {}
             else:
-                data = json.load(file)
+                if file_path.endswith("json.gz"):
+                    data = json.load(helper.limitedGzipFile(fileobj=file))
+                else:
+                    data = json.load(file)
         except Exception, err:
             self.log.debug("Json file %s load error: %s" % (file_path, err))
             data = {}
diff --git a/src/Site/SiteStorage.py b/src/Site/SiteStorage.py
index 41c4a14e..bfdd7840 100644
--- a/src/Site/SiteStorage.py
+++ b/src/Site/SiteStorage.py
@@ -85,7 +85,7 @@ class SiteStorage(object):
             # Data files in content.json
             content_inner_path_dir = helper.getDirname(content_inner_path)  # Content.json dir relative to site
             for file_relative_path in content.get("files", {}).keys() + content.get("files_optional", {}).keys():
-                if not file_relative_path.endswith(".json"):
+                if not file_relative_path.endswith(".json") and not file_relative_path.endswith("json.gz"):
                     continue  # We only interesed in json files
                 file_inner_path = content_inner_path_dir + file_relative_path  # File Relative to site dir
                 file_inner_path = file_inner_path.strip("/")  # Strip leading /
@@ -239,7 +239,7 @@ class SiteStorage(object):
             if self.has_db:
                 self.closeDb()
                 self.openDb()
-        elif not config.disable_db and inner_path.endswith(".json") and self.has_db:  # Load json file to db
+        elif not config.disable_db and (inner_path.endswith(".json") or inner_path.endswith(".json.gz")) and self.has_db:  # Load json file to db
             if config.verbose:
                 self.log.debug("Loading json file to db: %s (file: %s)" % (inner_path, file))
             try: