M-DOC-FULL P2 | EPUB read_epub_metadata 与 read_epub_chapters 重复 ZIP 解析 #98

Closed
opened 2026-06-07 21:49:07 +08:00 by wangdl · 1 comment
Owner

问题

epub.rsread_epub_metadata()read_epub_chapters() 各自独立执行:

  1. fs::File::open → 打开文件
  2. ZipArchive::new → 解析 ZIP
  3. read_opf → 读取 container.xml + OPF
  4. parse_opf → 解析 manifest/spine

两次调用会重复执行全部步骤。

建议

合并为单次读取:read_epub(file_path) -> Result<EpubData, _>,返回 EpubData { metadata: EpubMetadata, chapters: Vec<EpubChapter> }

代码位置

crates/zx_document_core/src/epub.rs:30-73

审计来源

#71-#74 批审查发现。

## 问题 `epub.rs` 中 `read_epub_metadata()` 和 `read_epub_chapters()` 各自独立执行: 1. `fs::File::open` → 打开文件 2. `ZipArchive::new` → 解析 ZIP 3. `read_opf` → 读取 container.xml + OPF 4. `parse_opf` → 解析 manifest/spine 两次调用会重复执行全部步骤。 ## 建议 合并为单次读取:`read_epub(file_path) -> Result<EpubData, _>`,返回 `EpubData { metadata: EpubMetadata, chapters: Vec<EpubChapter> }`。 ## 代码位置 `crates/zx_document_core/src/epub.rs:30-73` ## 审计来源 #71-#74 批审查发现。
Author
Owner

修复完成

问题

read_epub_metadata()read_epub_chapters() 各自独立执行 ZIP 打开 + OPF 解析,调用两次等于重复全部步骤。

修复

新增 read_epub(file_path) -> EpubData — 单次 ZIP 打开 + OPF 解析,同时返回 metadata + chapters:

pub struct EpubData {
    pub metadata: EpubMetadata,
    pub chapters: Vec<EpubChapter>,
}
pub fn read_epub(file_path: &Path) -> Result<EpubData, DocumentError> {
    // open ZIP once → parse OPF once → build both metadata and chapters
}

read_epub_metadataread_epub_chapters 现在委托到 read_epub,保持向后兼容。

验证

cargo test epub — 12 passed
## 修复完成 ### 问题 `read_epub_metadata()` 和 `read_epub_chapters()` 各自独立执行 ZIP 打开 + OPF 解析,调用两次等于重复全部步骤。 ### 修复 新增 `read_epub(file_path) -> EpubData` — 单次 ZIP 打开 + OPF 解析,同时返回 metadata + chapters: ```rust pub struct EpubData { pub metadata: EpubMetadata, pub chapters: Vec<EpubChapter>, } pub fn read_epub(file_path: &Path) -> Result<EpubData, DocumentError> { // open ZIP once → parse OPF once → build both metadata and chapters } ``` `read_epub_metadata` 和 `read_epub_chapters` 现在委托到 `read_epub`,保持向后兼容。 ### 验证 ``` cargo test epub — 12 passed ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/zhixi-document-runtime#98
No description provided.