Skip to content

Commit a2e42d1

Browse files
donislawdevclaude
andcommitted
format/zip: an archive that holds real files, exact to the byte
The fourth format and the first container. The entries are not random bytes - they are real generated files of another format, each one valid on its own. Asking for five PDFs of 200 kB inside a 3 MB archive gives exactly 3 145 728 bytes, and every extracted PDF opens. ZIP is the only Tier 1 format whose padding channel has a ceiling, so it is the only one that really needs both stages of the size strategy: the archive comment up to 65 535 bytes, then a stored entry above it. Measured: 7-Zip reports no warning at any comment size up to the limit, and the entry overhead is a constant plus twice the name length, with data and comment both counting one for one. Everything is stored rather than compressed, so the size is a linear function of the parts and planning computes it exactly. The interesting part is what was removed rather than added. This project had designed the engine to inject a child producing function into the archive generator, so the archive would not reach upwards for the engine. The reasoning was right that reaching for the engine breaks the layering. The conclusion was wrong: an archive needs the registry and another generator, and both already sit on its own layer, where a sideways edge is allowed. So the injection solved a problem that does not exist. It was removed before it was written and the architecture note now says so. An abstraction built ahead of a need is a cost, not a safeguard. Verified with 7-Zip, Windows Explorer, the built in Expand-Archive, and by extracting the contents and opening them with a PDF reader. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 133bfc3 commit a2e42d1

4 files changed

Lines changed: 385 additions & 2 deletions

File tree

‎CHANGELOG-DEV.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@ configuration, architectural decisions. Anything a user would notice goes to
66

77
## Unreleased
88

9+
### 2026-08-01 - ZIP, and an abstraction that turned out unnecessary
10+
11+
- `zip` is the fourth generator and the first container. Entries are real
12+
generated files of another format, each valid on its own.
13+
- **The two stage padding strategy in its pure form.** ZIP is the only Tier 1
14+
format whose padding channel has a ceiling, so it is the only one that
15+
really needs both stages: the archive comment up to 65 535 bytes, then a
16+
stored entry above it. Measured: 7-Zip reports no warning at any comment
17+
size up to the limit.
18+
- Everything is stored rather than compressed, so the archive size is a
19+
linear function of its parts and planning computes it exactly. Measured:
20+
entry overhead is a constant plus twice the name length, data and comment
21+
both count one for one.
22+
- **The child generator injection this project designed was not needed.** The
23+
architecture note had the engine injecting a child producing function into
24+
the archive generator, to avoid the archive reaching upwards for the
25+
engine. Reaching for the engine would indeed have broken the layering - but
26+
an archive needs the registry and another generator, and both sit on its
27+
own layer. format.Get is a sideways edge that was already allowed. The
28+
machinery was removed before it was written and the note corrected.
29+
- `entry_size` accepts the same size syntax as --size. Anything else would
30+
have meant entry_size=200kb failing while size=200kb works.
31+
- Nesting an archive inside an archive is refused for now, because it needs a
32+
depth limit first and there is none.
33+
- Guards: 33, all green with four formats registered. Five mutations of the
34+
ZIP generator all turn them red.
35+
936
### 2026-08-01 - PDF, and an assumption of ours disproved
1037

1138
- `pdf` is the third generator. Exact size, byte determinism, pages and page

‎CHANGELOG.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ because it turns other people's test suites red.
1212

1313
### Added
1414

15-
- `tfg generate` produces **text, PNG and PDF files** of an exact size. Ask
16-
for 10 485 761 bytes and you get exactly that.
15+
- `tfg generate` produces **text, PNG, PDF and ZIP files** of an exact size.
16+
Ask for 10 485 761 bytes and you get exactly that.
17+
- **A ZIP holds real generated files, not random bytes.**
18+
`--set entries=5 --set entry_format=pdf --set entry_size=200kb` gives an
19+
archive whose five entries are valid PDFs that open on their own. Checked
20+
with 7-Zip, Windows Explorer and by extracting and opening the contents.
1721
- PDF takes `--set pages=` and `--set page_size=` (A4, A3, A5, Letter,
1822
Legal). The label goes in the page footer and in the document title.
1923
Checked against Xpdf, exiftool and the Windows PDF renderer.

‎internal/format/all/all.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ import (
1111
_ "github.com/donislawdev/TestingFilesGenerator/internal/format/pdf"
1212
_ "github.com/donislawdev/TestingFilesGenerator/internal/format/png"
1313
_ "github.com/donislawdev/TestingFilesGenerator/internal/format/txt"
14+
_ "github.com/donislawdev/TestingFilesGenerator/internal/format/zip"
1415
)

0 commit comments

Comments
 (0)