Decompressing a file

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Decompressing a file

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does decompression do to a compressed file?
A Makes the file smaller again
B Reverses compression to make the file usable again
2. You unzip a ZIP file of your Year 10 assignment. What do you get back?
A The exact original files
B Lower quality copies of the files
3. Which type of compression can be fully reversed by decompression?
A Lossy compression
B Lossless compression
4. You save a photo as a low quality JPEG, then open it again. Can you get the original detail back?
A No, the removed detail is gone for good
B Yes, decompressing brings back all the detail
5. Which is true about decompressing a lossy file?
A It only rebuilds an approximation of the original
B It rebuilds a perfect copy of the original

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1unzip photos.zip AA ZIP file must be unzipped (decompressed) first to get usable files back. Unzipping restores the originals exactly.
2decompress(song.mp3) Boriginal == decompress(compress(original))
3Lossless decompression gives back a file identical to the original CJPG is lossy, so opening or decompressing it cannot restore the exact original. The removed detail is gone for good.
4A lossy file cannot be restored to the original after decompression DTurns the MP3 back into playable sound, but the detail removed when it was made is not restored
5Open photo.jpg to get the exact original back Eoriginal != decompress(compress_lossy(original))
6A ZIP file must be used without unzipping FDecompresses a ZIP archive so the original files are restored exactly, because ZIP is lossless

Definitions

decompression

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
import zipfile z = zipfile.ZipFile("photos.zip") z.__________("photos")
2.
letter = "A" count = 5 decoded = letter _ count
3.
original = "AAAABBB" restored = decompress(compress(original)) print(original __ restored)
4.
method = "lossless" __ method == "lossless": print("Exact original restored")
5.
original = "AAAAABB" packed = compress(original) restored = __________(packed)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A method ← "lossy"
B restored ← decompress(zip)
C IF restored = original THEN
D OUTPUT "Exact copy"
E ENDIF
Question 2
A zip ← "report.zip"
B files ← compress(zip)
C OUTPUT files
Question 3
A file ← "holiday.jpg"
B type ← "lossy"
C OUTPUT "Original restored"
Question 4
A IF method = "lossy" THEN
B OUTPUT "Exact original"
C ELSE
D OUTPUT "Data lost for good"
E ENDIF
Question 5
A zip ← "essay.zip"
B essay ← unzip(zip)
C OPEN zip

Answer Key

Decompressing a file
Section A: Quick Questions
Q1
B — Reverses compression to make the file usable again
Q2
A — The exact original files
Q3
B — Lossless compression
Q4
A — No, the removed detail is gone for good
Q5
A — It only rebuilds an approximation of the original
Section B: Match the Pairs
Q1
unzip photos.zip → Decompresses a ZIP archive so the original files are restored exactly, because ZIP is lossless
Q2
decompress(song.mp3) → Turns the MP3 back into playable sound, but the detail removed when it was made is not restored
Q3
Lossless decompression gives back a file identical to the original → original == decompress(compress(original))
Q4
A lossy file cannot be restored to the original after decompression → original != decompress(compress_lossy(original))
Q5
Open photo.jpg to get the exact original back → JPG is lossy, so opening or decompressing it cannot restore the exact original. The removed detail is gone for good.
Q6
A ZIP file must be used without unzipping → A ZIP file must be unzipped (decompressed) first to get usable files back. Unzipping restores the originals exactly.
Section C: Definitions
Q1
decompression — Reversing compression to turn a compressed file back into usable data. Only lossless decompression restores the exact original; lossy data that was removed is gone for good.
Section D: Fill in the Blanks
Q1
import zipfile z = zipfile.ZipFile("photos.zip") z.extractall("photos")
Q2
letter = "A" count = 5 decoded = letter * count
Q3
original = "AAAABBB" restored = decompress(compress(original)) print(original == restored)
Q4
method = "lossless" if method == "lossless": print("Exact original restored")
Q5
original = "AAAAABB" packed = compress(original) restored = decompress(packed)
Section E: Spot the Error
Q1
A — Only lossless decompression gives back an exact copy of the original. With a lossy method the program would not print "Exact copy". Line 1 should be method ← "lossless".
Q2
B — Unzipping a ZIP file is decompression, which reverses compression. Calling compress() would shrink the file again. It should be files ← unzip(zip).
Q3
C — A lossy file like a JPEG has had data permanently removed, so decompression cannot restore the original. The output should say the original cannot return.
Q4
A — The exact original is only restored when the method is lossless. The condition should test method = "lossless". Otherwise the messages are the wrong way round.
Q5
C — The ZIP file is still compressed, so it is not usable data yet. After decompressing, the program should open the extracted file: OPEN essay.