diff --git a/tools/deploy_s3.py b/tools/deploy_s3.py index 025cad812..2fda7fe09 100644 --- a/tools/deploy_s3.py +++ b/tools/deploy_s3.py @@ -105,8 +105,8 @@ def deploy_to_s3_main( # compression received by the end user (since the CDN re-compresses # files). fh_compressed = io.BytesIO() - with gzip.GzipFile(fileobj=fh_compressed, mode="w"): - shutil.copyfileobj(fh_in, fh_compressed) + with gzip.GzipFile(fileobj=fh_compressed, mode="wb") as gzip_file: + shutil.copyfileobj(fh_in, gzip_file) fh_compressed.seek(0) diff --git a/tools/tests/test_deploy_s3.py b/tools/tests/test_deploy_s3.py index 999c3b7a0..fed1f0f1e 100644 --- a/tools/tests/test_deploy_s3.py +++ b/tools/tests/test_deploy_s3.py @@ -1,4 +1,7 @@ +import gzip +import io import re +import shutil import sys from pathlib import Path, PurePosixPath @@ -93,6 +96,7 @@ def test_deploy_to_s3_overwrite(tmp_path, capsys): @mock_s3 def test_deploy_to_s3_mime_type(tmp_path, capsys): + """Test that we set the correct MIME type for each file extension""" for ext in ["whl", "tar", "zip", "js", "ts", "json", "ttf", "a", "mjs.map", "mjs"]: (tmp_path / f"a.{ext}").write_text("a") @@ -129,3 +133,10 @@ def test_deploy_to_s3_mime_type(tmp_path, capsys): assert get_header("a.json") == "application/json" assert get_header("a.ttf") == "font/ttf" assert get_header("a.mjs.map") == "binary/octet-stream" + + # Test that we can read the data back + res = s3_client.get_object(Bucket=bucket_name, Key="a.js") + stream = io.BytesIO() + with gzip.GzipFile(fileobj=res["Body"], mode="r") as fh: + shutil.copyfileobj(fh, stream) + assert stream.getvalue() == b"a"