~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Ian Clatworthy
  • Date: 2009-02-25 07:01:31 UTC
  • mto: (4171.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 4173.
  • Revision ID: ian.clatworthy@canonical.com-20090225070131-wjq5cy6ueuf2wqdi
added osutils.size_sha_file() with tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
597
597
    return s.hexdigest()
598
598
 
599
599
 
 
600
def size_sha_file(f):
 
601
    """Calculate the size and hexdigest of an open file.
 
602
 
 
603
    The file cursor should be already at the start and
 
604
    the caller is responsible for closing the file afterwards.
 
605
    """
 
606
    size = 0
 
607
    s = sha()
 
608
    BUFSIZE = 128<<10
 
609
    while True:
 
610
        b = f.read(BUFSIZE)
 
611
        if not b:
 
612
            break
 
613
        size += len(b)
 
614
        s.update(b)
 
615
    return size, s.hexdigest()
 
616
 
 
617
 
600
618
def sha_file_by_name(fname):
601
619
    """Calculate the SHA1 of a file by reading the full text"""
602
620
    s = sha()