dgelessus / python-typedstream

A pure Python, cross-platform library/tool for reading Mac OS X and NeXTSTEP typedstream files
GNU General Public License v3.0
22 stars 3 forks source link

Unarchiving of NSURL #1

Closed RamseyK closed 1 year ago

RamseyK commented 1 year ago

Thanks for this great library. Added support for NSURL in a personal project. See diff below - don't care about credit happy to just move this forward.

@archiving.archived_class
class NSURL(NSObject):
    value: str

    def _init_from_unarchiver_(self, unarchiver: archiving.Unarchiver, class_version: int) -> None:
        if class_version != 0:
            raise ValueError(f"Unsuppored version: {class_version}")

        # unk flag
        unarchiver.decode_value_of_type(b"c")

        # URL string
        _nsstr_rep = unarchiver.decode_value_of_type(b"@")
        self.value = _nsstr_rep.value

    def __repr__(self) -> str:
        return f"{type(self).__name__}({self.value!r})"
dgelessus commented 1 year ago

Thank you, and sorry for the really late reply! I've integrated a variant of this now. (I also figured out the unknown flag - it's used for relative URLs.)

By the way, I've also properly released this library on PyPI now: https://pypi.org/project/pytypedstream/