diff mbox series

[layerindex-web,2/3] dockersetup.py: databasefile zstd compression

Message ID 20231006024422.38381-2-tim.orling@konsulko.com
State Accepted, archived
Commit d020a5c04e1659d631e5c3064d7ca4021a82d170
Delegated to: Tim Orling
Headers show
Series [layerindex-web,1/3] build(deps): bump pillow from 9.3.0 to 10.0.1 | expand

Commit Message

Tim Orling Oct. 6, 2023, 2:44 a.m. UTC
zstd compression and decompression are significantly faster than gzip.
zstd is also "splittable" and is streaming/real-time friendly.

Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 dockersetup.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/dockersetup.py b/dockersetup.py
index 6a0ab67..d6e8f33 100755
--- a/dockersetup.py
+++ b/dockersetup.py
@@ -4,6 +4,8 @@ 
 #
 # Copyright (C) 2018 Intel Corporation
 # Author: Amber Elliot <amber.n.elliot@intel.com>
+# Copyright (C) 2023 Konsulko Group
+# Author: Tim Orling <tim.orling@konsulko.com>
 #
 # Licensed under the MIT license, see COPYING.MIT for details
 #
@@ -52,7 +54,7 @@  def get_args():
     parser.add_argument('-s', '--https-proxy', type=str, help='https proxy in the format http://<myproxy:port>', default=default_https_proxy, required=False)
     parser.add_argument('-S', '--socks-proxy', type=str, help='socks proxy in the format socks://myproxy:port>', default=default_socks_proxy, required=False)
     parser.add_argument('-N', '--no-proxy', type=str, help='Comma-separated list of hosts that should not be connected to via the proxy', default=default_no_proxy, required=False)
-    parser.add_argument('-d', '--databasefile', type=str, help='Location of your database file to import. Must be a .sql or .sql.gz file.', required=False)
+    parser.add_argument('-d', '--databasefile', type=str, help='Location of your database file to import. Must be a .sql, .sql.gz or .sql.zstd file.', required=False)
     parser.add_argument('-e', '--email-host', type=str, help='Email host for sending messages (optionally with :port if not 25)', required=False)
     parser.add_argument('--email-user', type=str, help='User name to use when connecting to email host', required=False)
     parser.add_argument('--email-password', type=str, help='Password to use when connecting to email host', required=False)
@@ -804,9 +806,15 @@  while True:
 if not args.update:
     # Import the user's supplied data
     if args.databasefile:
-        return_code = subprocess.call("gunzip -t %s > /dev/null 2>&1" % quote(args.databasefile), shell=True)
-        if return_code == 0:
-            catcmd = 'zcat'
+        filename, file_extension = os.path.splitext(args.databasefile)
+        if file_extension == ".zstd":
+            return_code = subprocess.call("zstd -t %s > /dev/null 2>&1" % quote(args.databasefile), shell=True)
+            if return_code == 0:
+                catcmd = 'zstdcat'
+        elif file_extension == ".gz":
+            return_code = subprocess.call("gunzip -t %s > /dev/null 2>&1" % quote(args.databasefile), shell=True)
+            if return_code == 0:
+                catcmd = 'zcat'
         else:
             catcmd = 'cat'
         env = os.environ.copy()