Skip to content

Commit eb180d8

Browse files
author
Kazuki Suzuki
authored
Add files via upload
1 parent 4bccad5 commit eb180d8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pyneofile.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ def _normalize_algo(algo):
9393
return 'auto'
9494
return a
9595

96+
def _normalize_ver_digits(ver_text):
97+
"""
98+
Make the on-disk version match Archive's strict header check:
99+
- remove dots
100+
- strip leading zeros by int() cast when numeric
101+
Falls back to the raw digits if not purely numeric.
102+
"""
103+
raw = ver_text.replace(".", "")
104+
try:
105+
return str(int(raw)) # "001" -> "1"
106+
except ValueError:
107+
return raw # keep as-is if not numeric
108+
96109
def _compress_bytes(data, algo='none', level=None):
97110
"""Return (stored_bytes, used_algo)."""
98111
algo = _normalize_algo(algo)
@@ -440,7 +453,7 @@ def _get(name, default=None):
440453
ext = _get('extension', '.neo')
441454

442455
delim_real = _decode_delim_escape(delim)
443-
ver_digits = _ver_digits(ver)
456+
ver_digits = _normalize_ver_digits(_ver_digits(ver))
444457

445458
spec = {
446459
'format_magic': magic,
@@ -511,7 +524,7 @@ def _checksum(data, cstype, text=False):
511524
def _write_global_header(fp, numfiles, encoding, checksumtype, extradata, formatspecs):
512525
delim = formatspecs['format_delimiter']
513526
magic = formatspecs['format_magic']
514-
ver_digits = _ver_digits(formatspecs.get('format_ver','001'))
527+
ver_digits = _normalize_ver_digits(_ver_digits(formatspecs.get('format_ver','001')))
515528

516529
# extras blob: count + items
517530
if isinstance(extradata, dict) and extradata:

0 commit comments

Comments
 (0)