'Python Decompress data returned from zip file in AWS S3

I have bytes returned by

s3.get_object(Bucket=bucket, Key=key
                    , Range="bytes=%d-%d" % (start, end)
            )

from a zip file stored in AWS S3.

The output is as below:

b'PK\x03\x04\x14\x00\x00\x00\x08\x00b\x06)T)Ih\xa4\x1c\x02\x00\x00\x08\x0b\x00\x00u\x00\x1c\x00mnt/d/repositories/Entertainment-Industry-Retailer-DataWarehouse/source_system_data/20220108/jupiter/state_format.xmlUT\t\x00\x03\x1f\xe4\xd9a\x1f\xe4\xd9aux\x0b\x00\x01\x04\xe8\x03\x00\x00\x04\xe8\x03\x00\x00\xdd\x96[o\xda@\x10\x85\xcfs\xa5\xfe\x07\x94\xe7\x96\xc4\\\x12\t\xd1D)\xb9!\x11\xd2\x02iS)\x12\xa2\tIP\xc1P\xec\xf4\xf2\xe7\xdb~3F\x90\xd6izQ1Re\xd9\x9e\x9d\xd9\xd9s\xce\xacw\xbd_\xbfT\xb5\xa3O\x1ai\xa8\x9c>\xa8\xaf\xa9"\r4V\xa8gZS\xa0\xbc6x\xefh[\x8f\xf5HU=WM/t\xa0\x13\xb5t\xac]u\xc8K\xf2C2-\xe7F1\xd7D\x15\xadsE\xba\xc0\xd3\xa7G\x0f;\xcf{\x80g\nB\xc4}E\xcf<\xed1~\xeb\xfb\x9eq"g\x91pYW\x01\xfc\r\x95\xb0\xde\xea\x96\xe8;\xee1c]\xe2\xb9\xc2\x9a\xfa\xc81\xb8wyT\xb0MG\x9a\xcfG\xbf\xf2\xdcE\x9e\x96\x7f=G\t\xb0\xceP\xd5P\xfb\x0e\xeb\xa7\x8ccc\xc6\xd8!\xfe>c&\xd5\xc8Q\x8f\x96\xf6\xa9\x88Uco\xee5\xff\x81\xeaD\x1axsX{\xb3j&,\x8dY\x85\xf1>\xc3\xaa\xef\x91\x1ah=\xb8t\\\xf5\xc8\xfbu\xc8\xb7\x1a\xd7\xd5\xf4:\x1b\x86\xf5}\xe2Q\xab\xfd\x99\xba \xec\x13?$~\xe4\xd1\x82G\x8dQ\x83\xcb\xf2\xea\xd8M\x8f\xb5\xf5\x12\x9f\xe5X\xc5LU@\xeb\x10\xcc\xd0q{T\xaf\xeb\xf3\x1b\xf8\xbb\xces\x97\xac5\xea\xf2+m\x85\x0c\xb4\x95\xfd[\\\x85\xbab\x06\xea\x02\xff\x06W\xa3\xaf\x94\x91\xbe\xd5\xa8+g\xa2\xae\xf0[\\6\xff\xebu\xb2\xf5O'

This is content of a file within the zip file.

I want to get the contents of this in string format. I know this is a xmlf file (if you look at the output you will find the file name in the header returned).

Basically I am trying to get file contents of a specific file (archive member) without downloading the whole zip file.

Your help is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source