~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: John Arbash Meinel
  • Date: 2009-01-23 21:20:55 UTC
  • mto: This revision was merged to the branch mainline in revision 3958.
  • Revision ID: john@arbash-meinel.com-20090123212055-qsa1szqtrrxtwgdl
Add report_activity to osutils.pumpfile

Show diffs side-by-side

added added

removed removed

Lines of Context:
508
508
    return False
509
509
 
510
510
 
511
 
def pumpfile(from_file, to_file, read_length=-1, buff_size=32768):
 
511
def pumpfile(from_file, to_file, read_length=-1, buff_size=32768,
 
512
             report_activity=None, direction='read'):
512
513
    """Copy contents of one file to another.
513
514
 
514
515
    The read_length can either be -1 to read to end-of-file (EOF) or
517
518
    The buff_size represents the maximum size for each read operation
518
519
    performed on from_file.
519
520
 
 
521
    :param report_activity: Call this as bytes are read, see
 
522
        Transport._report_activity
 
523
    :param direction: Will be passed to report_activity
 
524
 
520
525
    :return: The number of bytes copied.
521
526
    """
522
527
    length = 0
530
535
            if not block:
531
536
                # EOF reached
532
537
                break
 
538
            if report_activity is not None:
 
539
                report_activity(len(block), direction)
533
540
            to_file.write(block)
534
541
 
535
542
            actual_bytes_read = len(block)
542
549
            if not block:
543
550
                # EOF reached
544
551
                break
 
552
            if report_activity is not None:
 
553
                report_activity(len(block), direction)
545
554
            to_file.write(block)
546
555
            length += len(block)
547
556
    return length