~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Pool
  • Date: 2005-05-02 04:41:03 UTC
  • Revision ID: mbp@sourcefrog.net-20050502044102-ecf43538a15f1989
- Compute SHA-1 of files in chunks

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
 
93
93
def sha_file(f):
94
94
    import sha
95
 
    ## TODO: Maybe read in chunks to handle big files
96
95
    if hasattr(f, 'tell'):
97
96
        assert f.tell() == 0
98
97
    s = sha.new()
99
 
    s.update(f.read())
 
98
    BUFSIZE = 128<<10
 
99
    while True:
 
100
        b = f.read(BUFSIZE)
 
101
        if not b:
 
102
            break
 
103
        s.update(b)
100
104
    return s.hexdigest()
101
105
 
102
106
 
223
227
 
224
228
def compare_files(a, b):
225
229
    """Returns true if equal in contents"""
226
 
    # TODO: don't read the whole thing in one go.
227
230
    BUFSIZE = 4096
228
231
    while True:
229
232
        ai = a.read(BUFSIZE)