Last active
December 6, 2017 13:36
-
-
Save ilkermanap/69a22b07f40de13b394577fbee9b4aec to your computer and use it in GitHub Desktop.
Class for finding hashes without reading the whole file at once
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import platform | |
import hashlib | |
sistem = platform.system().lower() | |
if sistem == "linux" or sistem == "linux2" or sistem == "darwin": | |
SLASH = "/" | |
elif sistem == "windows": | |
SLASH = "\\" | |
class Dosya: | |
def __init__(self, yol): | |
self.adi = yol | |
self.stat = os.stat(self.adi) | |
self.dizin = yol[:yol.rfind(SLASH)] | |
self.hash_degeri = self.hash_bul() | |
def hash_bul(self, blksize=65536): | |
hasher = hashlib.sha256() | |
with open(self.adi, "rb") as infile: | |
buf = infile.read(blksize) | |
while len(buf) > 0: | |
hasher.update(buf) | |
buf = infile.read(blksize) | |
return hasher.hexdigest() | |
if __name__ == "__main__": | |
import sys | |
fname = sys.argv[1] | |
d = Dosya(fname) | |
print("Sha256 degeri :", d.hash_degeri," Boyutu :", d.stat.st_size) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment