Skip to content

Commit

Permalink
fixup: properly read gzipped content from S3
Browse files Browse the repository at this point in the history
We did not find a native way to do this from django-storages API.
  • Loading branch information
yohanboniface committed Dec 9, 2024
1 parent 5b88350 commit dfea3f1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion umap/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import shutil
import time
from gzip import GzipFile
from pathlib import Path

from botocore.exceptions import ClientError
Expand Down Expand Up @@ -106,7 +107,7 @@ def get_version(self, ref, instance):
)
except ClientError:
raise ValueError(f"Invalid version reference: {ref}")
return data["Body"].read()
return GzipFile(mode="r", fileobj=data["Body"]).read()

def get_version_path(self, ref, instance):
return self.url(instance.geojson.name, parameters={"VersionId": ref})
Expand Down
2 changes: 1 addition & 1 deletion umap/tests/test_datalayer_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_update_should_add_version(map, datalayer):

def test_get_version(map, datalayer):
assert len(datalayer.versions) == 1
datalayer.geojson = ContentFile('{"foo": "bar"}', "foo.json")
datalayer.geojson = ContentFile(b'{"foo": "bar"}', "foo.json")
datalayer.save()
assert len(datalayer.versions) == 2
latest = datalayer.versions[0]["ref"]
Expand Down

0 comments on commit dfea3f1

Please sign in to comment.