~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Robert Collins
  • Date: 2008-08-15 05:35:17 UTC
  • mto: This revision was merged to the branch mainline in revision 3677.
  • Revision ID: robertc@robertcollins.net-20080815053517-fjmv6jtns6s5ui9a
Add osutils.pump_string_file helper function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
569
569
    return length
570
570
 
571
571
 
 
572
def pump_string_file(bytes, file_handle, segment_size=None):
 
573
    """Write bytes to file_handle in many smaller writes.
 
574
 
 
575
    :param bytes: The string to write.
 
576
    :param file_handle: The file to write to.
 
577
    """
 
578
    # Write data in chunks rather than all at once, because very large
 
579
    # writes fail on some platforms (e.g. Windows with SMB  mounted
 
580
    # drives).
 
581
    if not segment_size:
 
582
        segment_size = 5242880 # 5MB
 
583
    segments = range(len(bytes) / segment_size + 1)
 
584
    write = file_handle.write
 
585
    for segment_index in segments:
 
586
        segment = buffer(bytes, segment_index * segment_size, segment_size)
 
587
        write(segment)
 
588
 
 
589
 
572
590
def file_iterator(input_file, readsize=32768):
573
591
    while True:
574
592
        b = input_file.read(readsize)