detect and decompress gzipped tile data

This commit is contained in:
Brandon Liu
2021-02-18 10:59:39 +08:00
parent f5f06b0b8a
commit ab8f1e889d

View File

@@ -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)))