Skip to content

add file info to local Item Assets #183

@ping-e84

Description

@ping-e84

Add a convenience method (or a set of them probably) that will add file info to each Item Asset (size, checksum, or whatever other fields from the STAC file info extension).

Suggested starting point (thank you @pjhartzell):

    @staticmethod
    def sha256sum_multihash(path: Path) -> str:
        with path.open('rb') as f:
            return str(
                multihash.wrap(
                    hashlib.file_digest(f, 'sha256').digest(),
                    'sha2-256',
                ).hex(),
            )

    def _add_fileinfo_to_assets(self, item: pystac.Item) -> None:
        for asset in item.assets.values():
            fext = FileExtension.ext(
                asset,
                add_if_missing=True,
            )
            path = Path(asset.href)

            if fext.checksum is None:
                fext.checksum = self.sha256sum_multihash(path)

            if fext.size is None:
                fext.size = path.stat().st_size

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions