From 7f54cf60989c76910b1f947385c81373063c2d48 Mon Sep 17 00:00:00 2001 From: zyb Date: Sat, 20 Jul 2024 05:38:38 +0800 Subject: [PATCH] modified: npk.py modified: patch.py --- npk.py | 133 +++++++++++++++++++++++++++++++++++++------------------ patch.py | 25 ++++++----- 2 files changed, 105 insertions(+), 53 deletions(-) diff --git a/npk.py b/npk.py index 0bb3575..2025a97 100644 --- a/npk.py +++ b/npk.py @@ -147,27 +147,52 @@ class NpkFileContainer: for item in self._items: yield item +class Package: + def __init__(self) -> None: + self._parts:list[NpkPartItem] = [] + def __iter__(self): + for part in self._parts: + yield part -class NovaPackage: + def __getitem__(self, id:NpkPartID): + for part in self._parts: + if part.id == id: + return part + part = NpkPartItem(id,b'') + self._parts.append(part) + return part + +class NovaPackage(Package): NPK_MAGIC = 0xbad0f11e def __init__(self,data:bytes=b''): - self._parts:list[NpkPartItem] = [] + super().__init__() + self._packages:list[Package] = [] offset = 0 + self._has_pkg = False while offset < len(data): part_id,part_size = struct.unpack_from('bytes: - for part in self._parts: + def get_digest(self,hash_fnc,package:Package=None)->bytes: + parts = package._parts if package else self._parts + for part in parts: data_header = struct.pack('