Skip to content

Instantly share code, notes, and snippets.

Last active Apr 8, 2020
What would you like to do?
SHA1 hashes of contents of TAR archive without extracting the archive first
import sys
import tarfile
import hashlib
for filename in sys.argv[1:]:
print filename
with, 'r') as tar:
for tarinfo in tar:
if tarinfo.isreg():
flo = tar.extractfile(tarinfo) # NB doesn't really extract the file, just gives you a stream (file-like-object) for reading it
hash = hashlib.sha1()
while True:
data =**20)
if not data:
print hash.hexdigest(),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment