diff options
| author | jvoisin | 2019-02-24 23:03:17 +0100 |
|---|---|---|
| committer | jvoisin | 2019-02-24 23:32:32 +0100 |
| commit | 545dccc3527fcdf851b30b072ae6c7222b711777 (patch) | |
| tree | 6c76bd51bd56a87aac7e70accc460c80d492253f /libmat2 | |
| parent | 524bae597209d775828bd176f6c00dd243f47c75 (diff) | |
In archive-based formats, the `mimetype` file comes first
This should improve epub compatibility,
along with other formats as a side-effect
Diffstat (limited to 'libmat2')
| -rw-r--r-- | libmat2/archive.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libmat2/archive.py b/libmat2/archive.py index d155664..1ae3b45 100644 --- a/libmat2/archive.py +++ b/libmat2/archive.py | |||
| @@ -4,13 +4,14 @@ import tempfile | |||
| 4 | import os | 4 | import os |
| 5 | import logging | 5 | import logging |
| 6 | import shutil | 6 | import shutil |
| 7 | from typing import Dict, Set, Pattern, Union, Any | 7 | from typing import Dict, Set, Pattern, Union, Any, List |
| 8 | 8 | ||
| 9 | from . import abstract, UnknownMemberPolicy, parser_factory | 9 | from . import abstract, UnknownMemberPolicy, parser_factory |
| 10 | 10 | ||
| 11 | # Make pyflakes happy | 11 | # Make pyflakes happy |
| 12 | assert Set | 12 | assert Set |
| 13 | assert Pattern | 13 | assert Pattern |
| 14 | assert List | ||
| 14 | assert Union | 15 | assert Union |
| 15 | 16 | ||
| 16 | 17 | ||
| @@ -115,9 +116,16 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 115 | temp_folder = tempfile.mkdtemp() | 116 | temp_folder = tempfile.mkdtemp() |
| 116 | abort = False | 117 | abort = False |
| 117 | 118 | ||
| 119 | items = list() # type: List[zipfile.ZipInfo] | ||
| 120 | for item in sorted(zin.infolist(), key=lambda z: z.filename): | ||
| 121 | if item.filename == 'mimetype': | ||
| 122 | items = [item] + items | ||
| 123 | else: | ||
| 124 | items.append(item) | ||
| 125 | |||
| 118 | # Since files order is a fingerprint factor, | 126 | # Since files order is a fingerprint factor, |
| 119 | # we're iterating (and thus inserting) them in lexicographic order. | 127 | # we're iterating (and thus inserting) them in lexicographic order. |
| 120 | for item in sorted(zin.infolist(), key=lambda z: z.filename): | 128 | for item in items: |
| 121 | if item.filename[-1] == '/': # `is_dir` is added in Python3.6 | 129 | if item.filename[-1] == '/': # `is_dir` is added in Python3.6 |
| 122 | continue # don't keep empty folders | 130 | continue # don't keep empty folders |
| 123 | 131 | ||
