Commit eebe867
Leo Ji
refactor: simplify _dedup_central_directory using NameToInfo
NameToInfo is already a {filename -> latest ZipInfo} mapping because
each writestr/write call does NameToInfo[name] = zinfo, so later writes
overwrite earlier ones (confirmed via CPython zipfile source).
Replace the manual seen/deduped loop with a two-liner that uses public API:
- namelist() to get all filenames (preserving insertion order)
- dict.fromkeys() to deduplicate while keeping first-seen order
- getinfo() to retrieve the latest ZipInfo for each unique name
Only filelist needs to be updated; NameToInfo is already correct and
does not need to be rewritten. The new list is computed before assignment
so the ZipFile is never left in an inconsistent state on exception.
Made-with: Cursor1 parent 9add837 commit eebe867
1 file changed
+13
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
140 | | - | |
141 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
142 | 147 | | |
143 | 148 | | |
144 | 149 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
157 | 155 | | |
158 | 156 | | |
159 | 157 | | |
| |||
0 commit comments