Skip to content

Conversation

@pressler-vsc
Copy link
Contributor

Description

When I tried to use hashlib.file_digest with a SubFile, I got an error because it was looking for a readable method that SubFile did not yet implement

While adding this method, I was curious why the static typing didn't find this. One reason is that many of the SubFile methods weren't type-annotated, but a bigger problem is that the protocol we declare does not match what we're doing in SubFile. Until Python gets its act together w.r.t. file-like objects, I propose just using typing.Any

Demo

import hashlib

import jbpy

nitf_path = "/host_shared/JITC_QuickLook_NITF/Quick-Look-Set-v2023.11.30/1. Format Constructs/POS/NITF_FMT_POS_01.NITF"

with open(nitf_path, "rb") as f:
    j = jbpy.Jbp()
    j.load(f)
    print(
        hashlib.file_digest(
            j["ImageSegments"][0]["Data"].as_filelike(f), "sha1"
        ).hexdigest()
    )

In main

$ python tmp.py 
Traceback (most recent call last):
ValueError: '<jbpy.core.SubFile object at 0x7fa756cefa10>' is not a file-like object in binary reading mode.

In this branch

$ python tmp.py 
90cea18ce80b94732a5cc532331db5123411c471

@pressler-vsc pressler-vsc merged commit 4adacbf into main Dec 16, 2025
5 checks passed
@pressler-vsc pressler-vsc deleted the subfile-readable branch December 16, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants