From a702c89aa5c9eb2b603caf8514f166f2f8488571 Mon Sep 17 00:00:00 2001 From: Jover Lee Date: Thu, 16 Nov 2023 09:52:45 -0800 Subject: [PATCH] remote: Add zstd to encoding types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows us to skip gzip compression when uploading .zst files. Includes adding ".zst" to the mimetypes encoding types dictionary because it is not yet included in the standard library.¹ ¹ https://github.com/python/cpython/blob/2ef3676a5bb8fba531fb8237ce50c27ebe37fb96/Lib/mimetypes.py#L411-L417 --- nextstrain/cli/remote/s3.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nextstrain/cli/remote/s3.py b/nextstrain/cli/remote/s3.py index a90d84a3..5769a644 100644 --- a/nextstrain/cli/remote/s3.py +++ b/nextstrain/cli/remote/s3.py @@ -65,6 +65,9 @@ mimetypes.add_type("application/json", ".json") mimetypes.add_type("text/markdown", ".md") +# Add zstd to encodings map since it is not yet included in the standard library +mimetypes.encodings_map[".zst"] = "zstd" + def upload(url: urllib.parse.ParseResult, local_files: List[Path], dry_run: bool = False) -> Iterable[Tuple[Path, str]]: """ @@ -281,6 +284,9 @@ def guess_type(path: Path) -> Tuple[str, Optional[str]]: >>> guess_type(Path("metadata.tsv.xz")) ('text/tab-separated-values', 'application/x-xz') + >>> guess_type(Path("metadata.tsv.zst")) + ('text/tab-separated-values', 'application/zstd') + >>> guess_type(Path("metadata.tsv.Z")) ('text/tab-separated-values', 'application/octet-stream') @@ -292,6 +298,7 @@ def guess_type(path: Path) -> Tuple[str, Optional[str]]: "gzip": "application/gzip", "xz": "application/x-xz", "bzip2": "application/x-bzip2", + "zstd": "application/zstd", } type, encoding = mimetypes.guess_type(path.name)