Skip to content

Instantly share code, notes, and snippets.

@moreati
Last active January 23, 2023 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moreati/0d4560eabfa910ba2e69f95c4f771365 to your computer and use it in GitHub Desktop.
Save moreati/0d4560eabfa910ba2e69f95c4f771365 to your computer and use it in GitHub Desktop.
List sha256 digests and names in a .tar piped to stdin
#!/usr/bin/env/python3
import hashlib
import sys
import tarfile
with tarfile.open(fileobj=sys.stdin.buffer, mode='r|') as tf:
for member in tf:
if member.isfile():
with tf.extractfile(member) as mf:
mh = hashlib.sha256(mf.read())
print(mh.hexdigest(), member.name)
@moreati
Copy link
Author

moreati commented Jan 23, 2023

$ zstdcat data.tar.zst | python tar_sum.py | tail -5
646957007887aed50d56c1f4fd9c6ef760d5b96d0a03577bda3492206dba1d05 ./usr/share/doc/linux-firmware/licenses/LICENSE.ivsc_firmware
af3caf873af21e925c9a05ba6753ecad69a5410e028ffcd4ef320bcd3f56eaa9 ./usr/share/doc/linux-firmware/licenses/LICENSE.nxp_mc_firmware.gz
c9223e485e35205f9e9546506389652bebec9473b8c3a20bcc292775e1888be0 ./usr/share/doc/linux-firmware/licenses/LICENSE.qcom.gz
fc6223d4bfe9f2f9e2eddc44b9fe5721d0caf49f01cb08d602906add686d8c6f ./usr/share/doc/linux-firmware/licenses/LICENSE.radeon
2bdd2e716f05d9737d3f9a20f9a3a3c0caee0e866100ddb0673f1178e42f92b9 ./usr/share/doc/linux-firmware/licenses/LICENSE.sdma_firmware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment