Skip to content

Commit

Permalink
remote: Add zstd to encoding types
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joverlee521 committed Nov 16, 2023
1 parent 4dc06eb commit a702c89
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nextstrain/cli/remote/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
"""
Expand Down Expand Up @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit a702c89

Please sign in to comment.