all2md.parsers.archive
Archive (TAR/7Z/RAR) parser that converts archive contents to AST representation.
This module provides the ArchiveToAstConverter class that extracts files from TAR, 7Z, and RAR archives, converts parseable files to AST, and handles resource files.
- class all2md.parsers.archive.ArchiveToAstConverter
Bases:
BaseParserConvert archive (TAR/7Z/RAR) contents to AST representation.
This parser extracts files from TAR, 7Z, and RAR archives, converts each parseable file to AST using the appropriate parser, and combines them into a unified document. Resource files (images, etc.) can be extracted to an attachment directory.
- Parameters:
options (ArchiveOptions or None) – Archive conversion options
Initialize the archive parser with options and progress callback.
- __init__(options: ArchiveOptions | None = None, progress_callback: Callable[[ProgressEvent], None] | None = None)
Initialize the archive parser with options and progress callback.
- parse(input_data: str | Path | IO[bytes] | bytes) Document
Parse archive into an AST Document.
- Parameters:
input_data (str, Path, IO[bytes], or bytes) – The input archive file to parse
- Returns:
AST Document node representing the parsed archive contents
- Return type:
- Raises:
ArchiveSecurityError – If archive fails security validation
MalformedFileError – If archive is corrupted or invalid
ParsingError – If parsing fails for other reasons
- convert_to_ast(archive: Any, archive_type: str) Document
Convert archive to AST Document.
- Parameters:
archive (Any) – Opened archive object (TarFile, SevenZipFile, or RarFile)
archive_type (str) – Type of archive
- Returns:
AST document node
- Return type:
- extract_metadata(archive: Any) DocumentMetadata
Extract metadata from archive.
- Parameters:
archive (Any) – Archive object (TarFile, SevenZipFile, or RarFile)
- Returns:
Extracted metadata (basic info about the archive)
- Return type: