Coverage for pyguymer3/gzip.py: 100%
7 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
1#!/usr/bin/env python3
3# Define function ...
4def gzip(
5 fname,
6 /,
7 *,
8 cwd = None,
9 gzipPath = None,
10 stderr = None,
11 stdout = None,
12 timeout = 60.0,
13):
14 """Compress a file using "gzip".
16 Parameters
17 ----------
18 fname : str
19 the name of the file to compress
20 cwd : str, optional
21 the child working directory (default None)
22 gzipPath : str, optional
23 the path to the "gzip" binary (if not provided then Python will attempt
24 to find the binary itself)
25 stderr : subprocess.PIPE, subprocess.DEVNULL, io.TextIOWrapper, optional
26 the destination of STDERR (default None)
27 stdout : subprocess.PIPE, subprocess.DEVNULL, io.TextIOWrapper, optional
28 the destination of STDOUT (default None)
29 timeout : float, optional
30 the timeout for any requests/subprocess calls
32 Notes
33 -----
34 I still need to provide justification for using this function over https://docs.python.org/3.12/library/gzip.html
36 Copyright 2017 Thomas Guymer [1]_
38 References
39 ----------
40 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3
41 """
43 # Import standard modules ...
44 import shutil
45 import subprocess
47 # **************************************************************************
49 # Try to find the paths if the user did not provide them ...
50 if gzipPath is None:
51 gzipPath = shutil.which("gzip")
52 assert gzipPath is not None, "\"gzip\" is not installed"
54 # Compress file ...
55 subprocess.run(
56 [
57 gzipPath,
58 "-9",
59 fname,
60 ],
61 check = True,
62 cwd = cwd,
63 encoding = "utf-8",
64 stderr = stderr,
65 stdout = stdout,
66 timeout = timeout,
67 )