0

I am working with gzip raw data that contains non-ASCII characters that I am unable to decompress and decode.

I am getting the data from Firestore through the python client and the payload looks like:

{'lastSchemaUpdateReason': 'new-app',
 'lastSchemaUpdateAt': DatetimeWithNanoseconds(2023, 10, 3, 18, 2, 38, 6000, tzinfo=datetime.timezone.utc),
 'schema': '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03íZÝRë6\x10~\x15\x8f§\x971´\x07\x0eC¹é\x00iJ\x18\x08\x84\x7fÎ)\x17\x8aµN\x14lÉHr\x02\x9cá%:½ï+ö\
18
  • It's binary data, why would you expect it to only contain ASCII characters? Commented Jul 9, 2024 at 21:32
  • I see. Is there a way to convert the gzip compressed binary? Commented Jul 9, 2024 at 21:37
  • I can'r reproduce the problem. with open('filename.gz', 'rb') as f: data = f.read(); expanded = gzip.decompress(data); print(expanded.decode()[:100]) Commented Jul 9, 2024 at 21:37
  • This assumes the original file was text before it was compressed. If not, just print expanded[:100] to see the first 100 bytes of the result. Commented Jul 9, 2024 at 21:38
  • Please post a minimal reproducible example Commented Jul 9, 2024 at 21:38

1 Answer 1

0

It seems that 'schema' is not specified properly.

The value currently saved in 'schema' looks as if it was just dragged and pasted from the output of print(the gzipped binary data).

If 'schema' contains binary gzipped data, it works well.

$ cat kk.txt
This is dummy data to make dummy gzip bin
$ gzip -k kk.txt
$ ls
kk.txt
kk.txt.gz
import gzip
from pathlib import Path


data_gzipped = Path("kk.txt.gz").read_bytes()
data = {'lastSchemaUpdateReason': 'new-app', 'schema': data_gzipped}
print(data)
print(gzip.decompress(data.get("schema")))
# result
# {'lastSchemaUpdateReason': 'new-app', 'schema': b'\x1f\x8b\x08\x08\xcd\xde\x8df\x00\x03kk.txt\x00\x0b\xc9\xc8,V\x00\xa2\x94\xd2\xdc\xdcJ\x85\x94\xc4\x92D\x85\x92|\x85\xdc\xc4\xecT\xa8PzUf\x81BRf\x1e\x17\x00\xa9\x12\xbd\x9c*\x00\x00\x00'}
# b'This is dummy data to make dummy gzip bin\n'

I recommend to check the code of assigning gzip data to schema variable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.