ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Tool_Box/NinoGenTools.py
(Generate patch)

Comparing Python/NinoCode/Tool_Box/NinoGenTools.py (file contents):
Revision 807 by nino.borges, Thu Dec 21 22:25:16 2023 UTC vs.
Revision 808 by nino.borges, Thu Dec 21 22:52:40 2023 UTC

# Line 10 | Line 10 | specific.
10  
11   """
12  
13 < import os, shutil, hashlib, time, stat, datetime
13 > import os, shutil, hashlib, time, stat, datetime, zipfile
14  
15   class Counter:
16      def __init__(self, count = 1):
# Line 85 | Line 85 | class HashFileContents:
85              print("Unsupported algorithm!")
86              hashVal = '0'
87          return hashVal
88 +    
89 +    def HashZipFileContents(self, absFilePath):
90 +        """This method will hash the contents of a zip file without having to extract it first.  The zip lib doesnt support the buffer API, which is why I do it this way."""
91 +        blocksize = 1024**2  #1M chunks
92 +        masterList = []
93 +
94 +        archive = zipfile.ZipFile(absFilePath)
95 +        for fname in archive.namelist():
96 +            entry = archive.open(fname)
97 +            if self.hashAlgorithm == 'md5':
98 +                hashContainer = hashlib.md5()
99 +            elif self.hashAlgorithm == 'sha1':
100 +                hashContainer = hashlib.sha1()
101 +            elif self.hashAlgorithm == 'sha224':
102 +                hashContainer = hashlib.sha224()
103 +            elif self.hashAlgorithm == 'sha256':
104 +                hashContainer = hashlib.sha256()
105 +            else:
106 +                print("Unsupported algorithm!")
107 +                hashContainer = False
108 +            if hashContainer:
109 +                while True:
110 +                    block = entry.read(blocksize)
111 +                    if not block:
112 +                        break
113 +                    hashContainer.update(block)
114 +                #print(fname, md5.hexdigest())
115 +                masterList.append([fname,hashContainer.hexdigest()])
116 +
117 +        return masterList
118  
119  
120   class FileProperties:

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)