Preserve optional content type strings in infe boxes

This commit is contained in:
Nymiro
2025-10-20 21:29:36 +13:00
parent 17f2fd893a
commit d857e5109a
2 changed files with 86 additions and 18 deletions
+4 -3
View File
@@ -1,6 +1,6 @@
# pyheic_struct/base.py
from typing import List
from typing import List, Optional
import struct
from io import BytesIO
@@ -65,6 +65,7 @@ class Box:
content_stream.write(child_data)
return content_stream.getvalue()
def build_box(self) -> bytes:
"""
构建完整的盒 (头部 + 内容),并返回其二进制数据。
@@ -80,7 +81,7 @@ class Box:
return header_data + content_data
def find_box(self, box_type: str, recursive: bool = True) -> 'Box' | None:
def find_box(self, box_type: str, recursive: bool = True) -> Optional['Box']:
"""在子盒中查找指定类型的第一个盒子"""
for child in self.children:
if child.type == box_type:
@@ -139,4 +140,4 @@ class FullBox(Box):
child_data = child.build_box()
content_stream.write(child_data)
return content_stream.getvalue()
return content_stream.getvalue()