cdindex2-parser 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chris K.Y. Fung
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.4
2
+ Name: cdindex2-parser
3
+ Version: 1.0.0
4
+ Summary: Parse CD Index 2 IDX/FILE files into CSV/JSON
5
+ Author-email: "Chris K.Y. Fung" <chris@example.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/chriskyfung/cdindex2-parser
8
+ Project-URL: Documentation, https://chriskyfung.github.io/cdindex2-parser/
9
+ Project-URL: Repository, https://github.com/chriskyfung/cdindex2-parser
10
+ Project-URL: Issues, https://github.com/chriskyfung/cdindex2-parser/issues
11
+ Project-URL: Changelog, https://github.com/chriskyfung/cdindex2-parser/blob/main/CHANGELOG.md
12
+ Keywords: cd-index,cdindex,parser,csv,json,legacy,dosdate,big5
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Utilities
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=8; extra == "dev"
29
+ Requires-Dist: pytest-cov>=5; extra == "dev"
30
+ Requires-Dist: coverage[toml]>=7; extra == "dev"
31
+ Requires-Dist: mypy>=1.11; extra == "dev"
32
+ Requires-Dist: ruff>=0.6; extra == "dev"
33
+ Requires-Dist: build>=1.2; extra == "dev"
34
+ Requires-Dist: twine>=5; extra == "dev"
35
+ Requires-Dist: pre-commit>=3.8; extra == "dev"
36
+ Provides-Extra: docs
37
+ Requires-Dist: mkdocs-material>=9.5; extra == "docs"
38
+ Requires-Dist: mkdocstrings[python]>=0.26; extra == "docs"
39
+ Dynamic: license-file
40
+
41
+ # CD Index 2 Parser
42
+
43
+ [![codecov](https://codecov.io/gh/chriskyfung/cdindex2-parser/graph/badge.svg?token=AHQ1APGM2W)](https://codecov.io/gh/chriskyfung/cdindex2-parser)
44
+ [![CI](https://github.com/chriskyfung/cdindex2-parser/actions/workflows/ci.yml/badge.svg)](https://github.com/chriskyfung/cdindex2-parser/actions/workflows/ci.yml)
45
+ [![PyPI](https://img.shields.io/pypi/v/cdindex2-parser)](https://pypi.org/project/cdindex2-parser/)
46
+ [![Python Versions](https://img.shields.io/pypi/pyversions/cdindex2-parser)](https://pypi.org/project/cdindex2-parser/)
47
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/chriskyfung/cdindex2-parser/blob/main/LICENSE)
48
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/chriskyfung/cdindex2-parser)
49
+
50
+ **CD Index 2 Parser** converts legacy `*.IDX` and `*.FILE` files from CD Index 2 (光碟索引大師) into modern CSV/JSON formats, preserving the full file tree structure, sizes, and modification timestamps.
51
+
52
+ This tool is for anyone who has old CD/DVD index catalogs from this popular legacy software and wants to access them with modern tools.
53
+
54
+ **📖 Full Documentation: https://chriskyfung.github.io/cdindex2-parser/**
55
+
56
+ ---
57
+
58
+ ## Features
59
+
60
+ - Parses file and directory structures from `.IDX` and `.FILE` pairs
61
+ - Correctly decodes the 32-bit MS-DOS FAT timestamps
62
+ - Reconstructs full file paths from tab-indented tree structures
63
+ - Outputs clean CSV or JSON
64
+ - Supports encodings like UTF-16, Big5, and CP950 for Traditional Chinese file names
65
+ - Zero runtime dependencies — pure Python standard library
66
+ - Typed API with frozen dataclasses — importable as a library
67
+
68
+ ---
69
+
70
+ ## Quick Start
71
+
72
+ Install from PyPI:
73
+
74
+ ```bash
75
+ pip install cdindex2-parser
76
+ ```
77
+
78
+ Parse a pair of `.IDX`/`.FILE` files into CSV:
79
+
80
+ ```bash
81
+ cdindex2-parser mydisk results.csv
82
+ ```
83
+
84
+ Or parse into JSON:
85
+
86
+ ```bash
87
+ cdindex2-parser mydisk results.json --format json
88
+ ```
89
+
90
+ Use it as a Python library:
91
+
92
+ ```python
93
+ from cdindex2_parser import parse_catalog
94
+
95
+ catalog = parse_catalog("mydisk.IDX", encoding="utf-16")
96
+ for entry in catalog:
97
+ print(f"{entry.path} is_dir={entry.is_dir} size={entry.size_bytes}")
98
+ ```
99
+
100
+ ---
101
+
102
+ ## 📖 Documentation
103
+
104
+ | Document | Link |
105
+ |---|---|
106
+ | Installation | [Docs › Installation](https://chriskyfung.github.io/cdindex2-parser/installation/) |
107
+ | Usage | [Docs › Usage](https://chriskyfung.github.io/cdindex2-parser/usage/) |
108
+ | File Format | [Docs › File Format](https://chriskyfung.github.io/cdindex2-parser/file-format/) |
109
+ | API Reference | [Docs › API Reference](https://chriskyfung.github.io/cdindex2-parser/api/) |
110
+ | Troubleshooting | [Docs › Troubleshooting](https://chriskyfung.github.io/cdindex2-parser/troubleshooting/) |
111
+
112
+ ---
113
+
114
+ ## License
115
+
116
+ MIT License. See [LICENSE](https://github.com/chriskyfung/cdindex2-parser/blob/main/LICENSE) for details.
@@ -0,0 +1,76 @@
1
+ # CD Index 2 Parser
2
+
3
+ [![codecov](https://codecov.io/gh/chriskyfung/cdindex2-parser/graph/badge.svg?token=AHQ1APGM2W)](https://codecov.io/gh/chriskyfung/cdindex2-parser)
4
+ [![CI](https://github.com/chriskyfung/cdindex2-parser/actions/workflows/ci.yml/badge.svg)](https://github.com/chriskyfung/cdindex2-parser/actions/workflows/ci.yml)
5
+ [![PyPI](https://img.shields.io/pypi/v/cdindex2-parser)](https://pypi.org/project/cdindex2-parser/)
6
+ [![Python Versions](https://img.shields.io/pypi/pyversions/cdindex2-parser)](https://pypi.org/project/cdindex2-parser/)
7
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/chriskyfung/cdindex2-parser/blob/main/LICENSE)
8
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/chriskyfung/cdindex2-parser)
9
+
10
+ **CD Index 2 Parser** converts legacy `*.IDX` and `*.FILE` files from CD Index 2 (光碟索引大師) into modern CSV/JSON formats, preserving the full file tree structure, sizes, and modification timestamps.
11
+
12
+ This tool is for anyone who has old CD/DVD index catalogs from this popular legacy software and wants to access them with modern tools.
13
+
14
+ **📖 Full Documentation: https://chriskyfung.github.io/cdindex2-parser/**
15
+
16
+ ---
17
+
18
+ ## Features
19
+
20
+ - Parses file and directory structures from `.IDX` and `.FILE` pairs
21
+ - Correctly decodes the 32-bit MS-DOS FAT timestamps
22
+ - Reconstructs full file paths from tab-indented tree structures
23
+ - Outputs clean CSV or JSON
24
+ - Supports encodings like UTF-16, Big5, and CP950 for Traditional Chinese file names
25
+ - Zero runtime dependencies — pure Python standard library
26
+ - Typed API with frozen dataclasses — importable as a library
27
+
28
+ ---
29
+
30
+ ## Quick Start
31
+
32
+ Install from PyPI:
33
+
34
+ ```bash
35
+ pip install cdindex2-parser
36
+ ```
37
+
38
+ Parse a pair of `.IDX`/`.FILE` files into CSV:
39
+
40
+ ```bash
41
+ cdindex2-parser mydisk results.csv
42
+ ```
43
+
44
+ Or parse into JSON:
45
+
46
+ ```bash
47
+ cdindex2-parser mydisk results.json --format json
48
+ ```
49
+
50
+ Use it as a Python library:
51
+
52
+ ```python
53
+ from cdindex2_parser import parse_catalog
54
+
55
+ catalog = parse_catalog("mydisk.IDX", encoding="utf-16")
56
+ for entry in catalog:
57
+ print(f"{entry.path} is_dir={entry.is_dir} size={entry.size_bytes}")
58
+ ```
59
+
60
+ ---
61
+
62
+ ## 📖 Documentation
63
+
64
+ | Document | Link |
65
+ |---|---|
66
+ | Installation | [Docs › Installation](https://chriskyfung.github.io/cdindex2-parser/installation/) |
67
+ | Usage | [Docs › Usage](https://chriskyfung.github.io/cdindex2-parser/usage/) |
68
+ | File Format | [Docs › File Format](https://chriskyfung.github.io/cdindex2-parser/file-format/) |
69
+ | API Reference | [Docs › API Reference](https://chriskyfung.github.io/cdindex2-parser/api/) |
70
+ | Troubleshooting | [Docs › Troubleshooting](https://chriskyfung.github.io/cdindex2-parser/troubleshooting/) |
71
+
72
+ ---
73
+
74
+ ## License
75
+
76
+ MIT License. See [LICENSE](https://github.com/chriskyfung/cdindex2-parser/blob/main/LICENSE) for details.
@@ -0,0 +1,94 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cdindex2-parser"
7
+ version = "1.0.0"
8
+ description = "Parse CD Index 2 IDX/FILE files into CSV/JSON"
9
+ authors = [{name = "Chris K.Y. Fung", email = "chris@example.com"}]
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ readme = "README.md"
13
+ requires-python = ">=3.10"
14
+ dependencies = []
15
+ keywords = ["cd-index", "cdindex", "parser", "csv", "json", "legacy", "dosdate", "big5"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Programming Language :: Python :: 3.14",
26
+ "Topic :: Utilities",
27
+ "Typing :: Typed",
28
+ ]
29
+
30
+
31
+
32
+ [tool.pytest.ini_options]
33
+ minversion = "8.0"
34
+ addopts = "-ra --strict-markers --strict-config"
35
+ testpaths = ["tests"]
36
+ pythonpath = ["src"]
37
+ xfail_strict = true
38
+ filterwarnings = ["error"]
39
+ [tool.ruff]
40
+ line-length = 88
41
+ target-version = "py310"
42
+ src = ["src", "tests"]
43
+
44
+ [tool.ruff.lint]
45
+ select = ["E", "F", "W", "I", "N", "UP", "B", "C4", "SIM", "RUF", "D", "PT", "S"]
46
+ ignore = ["D203", "D213"]
47
+
48
+ [tool.ruff.lint.per-file-ignores]
49
+ "tests/**" = ["D", "S101", "PLR2004"]
50
+
51
+ [tool.coverage.run]
52
+ branch = true
53
+ source = ["cdindex2_parser"]
54
+
55
+ [tool.coverage.report]
56
+ show_missing = true
57
+ fail_under = 80
58
+ exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:", "raise NotImplementedError"]
59
+
60
+ [project.optional-dependencies]
61
+ dev = [
62
+ "pytest>=8",
63
+ "pytest-cov>=5",
64
+ "coverage[toml]>=7",
65
+ "mypy>=1.11",
66
+ "ruff>=0.6",
67
+ "build>=1.2",
68
+ "twine>=5",
69
+ "pre-commit>=3.8",
70
+ ]
71
+ docs = ["mkdocs-material>=9.5", "mkdocstrings[python]>=0.26"]
72
+
73
+ [project.scripts]
74
+ cdindex2-parser = "cdindex2_parser.cli:main"
75
+
76
+ [project.urls]
77
+ Homepage = "https://github.com/chriskyfung/cdindex2-parser"
78
+ Documentation = "https://chriskyfung.github.io/cdindex2-parser/"
79
+ Repository = "https://github.com/chriskyfung/cdindex2-parser"
80
+ Issues = "https://github.com/chriskyfung/cdindex2-parser/issues"
81
+ Changelog = "https://github.com/chriskyfung/cdindex2-parser/blob/main/CHANGELOG.md"
82
+
83
+ [tool.setuptools.packages.find]
84
+ where = ["src"]
85
+ include = ["cdindex2_parser*"]
86
+
87
+ [tool.setuptools.package-data]
88
+ cdindex2_parser = ["py.typed"]
89
+
90
+ [tool.mypy]
91
+ python_version = "3.10"
92
+ files = ["src"]
93
+ strict = true
94
+ warn_unreachable = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,26 @@
1
+ """Public API for cdindex2-parser."""
2
+
3
+ from importlib.metadata import PackageNotFoundError, version
4
+
5
+ from .exporters import to_csv, to_json
6
+ from .models import Catalog, Entry, FileRecord, NameRecord
7
+ from .parser import parse_catalog, parse_file_line, parse_name_line, resolve_input_path
8
+
9
+ try:
10
+ __version__ = version("cdindex2-parser")
11
+ except PackageNotFoundError:
12
+ __version__ = "0.0.0+unknown"
13
+
14
+ __all__ = [
15
+ "Catalog",
16
+ "Entry",
17
+ "FileRecord",
18
+ "NameRecord",
19
+ "__version__",
20
+ "parse_catalog",
21
+ "parse_file_line",
22
+ "parse_name_line",
23
+ "resolve_input_path",
24
+ "to_csv",
25
+ "to_json",
26
+ ]
@@ -0,0 +1,6 @@
1
+ """Module entry point for ``python -m cdindex2_parser``."""
2
+
3
+ from .cli import main
4
+
5
+ if __name__ == "__main__":
6
+ raise SystemExit(main())
@@ -0,0 +1,89 @@
1
+ """Command-line interface for cdindex2-parser."""
2
+
3
+ import argparse
4
+ import sys
5
+ from collections.abc import Sequence
6
+ from importlib import metadata
7
+ from pathlib import Path
8
+
9
+ from .exporters import to_csv, to_json
10
+ from .models import Catalog
11
+ from .parser import parse_catalog, resolve_input_path
12
+
13
+
14
+ def build_parser() -> argparse.ArgumentParser:
15
+ """Build the argument parser for the CLI."""
16
+ parser = argparse.ArgumentParser(
17
+ prog="cdindex2-parser",
18
+ description="Parse CD Index 2 (光碟索引大師) IDX/FILE catalogs into CSV/JSON",
19
+ )
20
+ parser.add_argument(
21
+ "input",
22
+ help=(
23
+ "Base name or path of the IDX/FILE pair "
24
+ "(e.g. mydisk, mydisk.IDX, path/to/disk)"
25
+ ),
26
+ )
27
+ parser.add_argument(
28
+ "-o",
29
+ "--output",
30
+ required=False,
31
+ help="Output file path (CSV or JSON, inferred from suffix unless overridden)",
32
+ )
33
+ parser.add_argument(
34
+ "--format",
35
+ choices=["csv", "json"],
36
+ default=None,
37
+ help="Output format (csv or json); default inferred from --output suffix",
38
+ )
39
+ parser.add_argument(
40
+ "--encoding",
41
+ default="utf-16",
42
+ help="Input encoding (utf-16, big5, cp950); default utf-16 with BOM detection",
43
+ )
44
+ parser.add_argument(
45
+ "--version",
46
+ action="version",
47
+ version=f"cdindex2-parser {metadata.version('cdindex2-parser')}",
48
+ )
49
+ return parser
50
+
51
+
52
+ def main(argv: Sequence[str] | None = None) -> int:
53
+ """Parse arguments and run the conversion pipeline.
54
+
55
+ Returns an exit code suitable for ``sys.exit``.
56
+ """
57
+ parser = build_parser()
58
+ args = parser.parse_args(argv)
59
+
60
+ idx_path, _ = resolve_input_path(args.input)
61
+ try:
62
+ catalog: Catalog = parse_catalog(args.input, encoding=args.encoding)
63
+ except Exception as exc:
64
+ print(f"Error: {exc}", file=sys.stderr)
65
+ return 1
66
+
67
+ # Determine output path and format
68
+ output_path: str | Path
69
+ fmt: str
70
+
71
+ if args.output:
72
+ output_path = Path(args.output)
73
+ fmt = args.format or output_path.suffix.lstrip(".").lower() or "csv"
74
+ else:
75
+ # Default: same base name with .csv extension
76
+ base = Path(idx_path).with_suffix("")
77
+ output_path = base.with_suffix(".csv")
78
+ fmt = "csv"
79
+
80
+ if fmt == "csv":
81
+ to_csv(catalog, output_path)
82
+ elif fmt == "json":
83
+ to_json(catalog, output_path)
84
+ else:
85
+ print(f"Error: unknown format '{fmt}'", file=sys.stderr)
86
+ return 1
87
+
88
+ print(f"Wrote {fmt.upper()} output to {output_path}")
89
+ return 0
@@ -0,0 +1,30 @@
1
+ """Exception hierarchy for cdindex2-parser."""
2
+
3
+
4
+ class CDIndexError(Exception):
5
+ """Base exception for all cdindex2-parser errors."""
6
+
7
+
8
+ class InputNotFoundError(CDIndexError, FileNotFoundError):
9
+ """Raised when an input file cannot be found."""
10
+
11
+
12
+ class EncodingError(CDIndexError, UnicodeDecodeError):
13
+ """Raised when the input encoding is incorrect."""
14
+
15
+
16
+ class LineCountMismatchError(CDIndexError, ValueError):
17
+ """Raised when .IDX and .FILE line counts differ."""
18
+
19
+
20
+ class IndentMismatchError(CDIndexError, ValueError):
21
+ """Raised when an indentation mismatch is found."""
22
+
23
+
24
+ class MalformedRecordError(CDIndexError, ValueError):
25
+ """Raised when a record cannot be parsed."""
26
+
27
+ def __init__(self, message: str, line_number: int | None = None):
28
+ """Initialize with an optional line number for error context."""
29
+ self.line_number = line_number
30
+ super().__init__(message)
@@ -0,0 +1,74 @@
1
+ """CSV and JSON exporters for cdindex2-parser catalogs."""
2
+
3
+ import csv
4
+ import json
5
+ from collections.abc import Iterator
6
+ from pathlib import Path
7
+
8
+ from .models import Catalog
9
+
10
+ CSV_COLUMNS = ("FullPath", "IsDir", "SizeBytes", "MtimeStr")
11
+
12
+
13
+ def iter_rows(catalog: Catalog) -> Iterator[dict[str, object]]:
14
+ """Yield each ``Entry`` as a dict with CSV-column keys.
15
+
16
+ The ``mtime`` is formatted as an ISO-8601-compatible string
17
+ ``YYYY-MM-DDTHH:MM:SS``.
18
+ """
19
+ for entry in catalog:
20
+ mtime_str = entry.mtime.strftime("%Y-%m-%dT%H:%M:%S")
21
+ yield {
22
+ "FullPath": entry.path,
23
+ "IsDir": "1" if entry.is_dir else "0",
24
+ "SizeBytes": entry.size_bytes,
25
+ "MtimeStr": mtime_str,
26
+ }
27
+
28
+
29
+ def to_csv(catalog: Catalog, out: str | Path) -> None:
30
+ """Write a ``Catalog`` to CSV format.
31
+
32
+ The output uses ``newline=""`` (as recommended for ``csv.writer`` on
33
+ Windows) and ``csv.QUOTE_MINIMAL`` quoting.
34
+ """
35
+ out_path = Path(out)
36
+ with open(out_path, "w", encoding="utf-8", newline="") as f:
37
+ writer = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
38
+ writer.writerow(CSV_COLUMNS)
39
+ for row in iter_rows(catalog):
40
+ writer.writerow([row[c] for c in CSV_COLUMNS])
41
+
42
+
43
+ def to_json(catalog: Catalog, out: str | Path) -> None:
44
+ """Write a ``Catalog`` to JSON format.
45
+
46
+ Output schema version 1:
47
+
48
+ .. code-block:: json
49
+
50
+ {
51
+ "version": 1,
52
+ "entries": [
53
+ {
54
+ "path": "dir/file.txt",
55
+ "is_dir": false,
56
+ "size_bytes": 226,
57
+ "mtime": "2013-11-03T14:38:30"
58
+ }
59
+ ]
60
+ }
61
+ """
62
+ out_path = Path(out)
63
+ entries_data = [
64
+ {
65
+ "path": entry.path,
66
+ "is_dir": entry.is_dir,
67
+ "size_bytes": entry.size_bytes,
68
+ "mtime": entry.mtime.strftime("%Y-%m-%dT%H:%M:%S"),
69
+ }
70
+ for entry in catalog
71
+ ]
72
+ data = {"version": 1, "entries": entries_data}
73
+ with open(out_path, "w", encoding="utf-8") as f:
74
+ json.dump(data, f, ensure_ascii=False, indent=2)
@@ -0,0 +1,54 @@
1
+ """Data models for cdindex2-parser catalogs."""
2
+
3
+ from collections.abc import Iterator
4
+ from dataclasses import dataclass
5
+ from datetime import datetime
6
+
7
+ FILE_TYPE_DIR = "D"
8
+ FILE_TYPE_FILE = "F"
9
+
10
+
11
+ @dataclass(frozen=True, slots=True)
12
+ class FileRecord:
13
+ """A single record from a ``.FILE`` line."""
14
+
15
+ indent: int
16
+ type: str # "D" | "F"
17
+ size: int
18
+ ts: int
19
+ mtime: datetime
20
+
21
+
22
+ @dataclass(frozen=True, slots=True)
23
+ class NameRecord:
24
+ """A single record from a ``.IDX`` line."""
25
+
26
+ indent: int
27
+ name: str
28
+
29
+
30
+ @dataclass(frozen=True, slots=True)
31
+ class Entry:
32
+ """A resolved catalog entry with full path."""
33
+
34
+ depth: int
35
+ name: str
36
+ is_dir: bool
37
+ size_bytes: int
38
+ mtime: datetime
39
+ path: str
40
+
41
+
42
+ @dataclass(frozen=True, slots=True)
43
+ class Catalog:
44
+ """A collection of resolved catalog entries."""
45
+
46
+ entries: tuple[Entry, ...]
47
+
48
+ def __iter__(self) -> Iterator[Entry]:
49
+ """Iterate over the catalog entries."""
50
+ return iter(self.entries)
51
+
52
+ def __len__(self) -> int:
53
+ """Return the number of entries."""
54
+ return len(self.entries)