Round-trip a ZIP archive in memory
A ZIP file contains named entries, each with its own data. BytesIO gives zipfile a file-like object backed by memory, so a small archive can be created and read without leaving files behind.
Text still needs an explicit encoding before it becomes archive bytes. Reading an entry returns bytes again; decode it at the text boundary. This exercise reads named entries directly rather than extracting an archive to the filesystem. That keeps archive member names separate from local paths and makes the round trip independent of the current working directory.
import io, zipfile
buffer = io.BytesIO()
with zipfile.ZipFile(buffer, "w") as archive:
archive.writestr("note.txt", "Tea")
with zipfile.ZipFile(
io.BytesIO(buffer.getvalue())) as archive:
print(archive.read("note.txt").decode())Your task
Implement zip_texts(entries) returning ZIP bytes for a dictionary of names to text, encoded as UTF-8. unzip_texts(blob) reads all non-directory entries and returns the same mapping. Support an empty archive and Unicode text.
The explanation opens here once every check passes.