all2md.parsers.zip

ZIP archive parser that converts archive contents to AST representation.

This module provides the ZipToAstConverter class that extracts files from ZIP archives, converts parseable files to AST, and handles resource files.

class all2md.parsers.zip.ZipToAstConverter

Bases: BaseParser

Convert ZIP archive contents to AST representation.

This parser extracts files from ZIP 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 (ZipOptions or None) – ZIP conversion options

Initialize the ZIP parser with options and progress callback.

__init__(options: ZipOptions | None = None, progress_callback: Callable[[ProgressEvent], None] | None = None)

Initialize the ZIP parser with options and progress callback.

parse(input_data: str | Path | IO[bytes] | bytes) Document

Parse ZIP archive into an AST Document.

Parameters:

input_data (str, Path, IO[bytes], or bytes) – The input ZIP file to parse

Returns:

AST Document node representing the parsed archive contents

Return type:

Document

Raises:
convert_to_ast(zf: ZipFile) Document

Convert ZIP archive to AST Document.

Parameters:

zf (zipfile.ZipFile) – Opened ZIP file object

Returns:

AST document node

Return type:

Document

extract_metadata(zf: ZipFile) DocumentMetadata

Extract metadata from ZIP archive.

Parameters:

zf (zipfile.ZipFile) – ZIP file object

Returns:

Extracted metadata (basic info about the archive)

Return type:

DocumentMetadata