From ab8f1e889d5c4c57cb12397d4bd3ad22defd132c Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Thu, 18 Feb 2021 10:59:39 +0800 Subject: [PATCH] detect and decompress gzipped tile data --- python/pmtiles/writer.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/pmtiles/writer.py b/python/pmtiles/writer.py index 1c2ca6c..8ac70a7 100644 --- a/python/pmtiles/writer.py +++ b/python/pmtiles/writer.py @@ -1,3 +1,4 @@ +import gzip import itertools import json from contextlib import contextmanager @@ -20,6 +21,10 @@ class Writer: self.leaves = [] def write_tile(self,z,x,y,data): + # if the tile is GZIP-encoded, it won't work with range queries + # until transfer-encoding: gzip is well supported. + if data[0:2] == b'\x1f\x8b': + data = gzip.decompress(data) hsh = hash(data) if hsh in self.hash_to_offset: self.tiles.append((z,x,y,self.hash_to_offset[hsh],len(data)))