Question:
Write a program to compress and decompress the string “Global SQA!Global SQA!Global SQA!Global SQA!Global SQA!Global SQA!”
Use zlib.compress() and zlib.decompress() to compress and decompress a string.
Program:
1 2 3 4 5 6 7 8 9 |
import zlib s = 'Global SQA!Global SQA!Global SQA!Global SQA!Global SQA!Global SQA!' t = zlib.compress(s.encode()) print (t) print (zlib.decompress(t)) |
Explanation:
zlib.
compressobj
([level[, method[, wbits[, memlevel[, strategy]]]]])
Returns a compression object, to be used for compressing data streams that won’t fit into memory at once.
zlib.
decompress
(string[, wbits[, bufsize]])
Decompresses the data in string, returning a string containing the uncompressed data.
Output:
1 2 3 |
b"x\x9cs\xcf\xc9OJ\xccQ\x08\x0etTt'\x8f\t\x00\xc5\xa1\x14\xcb" b'Global SQA!Global SQA!Global SQA!Global SQA!Global SQA!Global SQA!' |
Leave a Reply