[BUG] transport/memory.py doesn't handle strings
John A Meinel
john at arbash-meinel.com
Wed Oct 19 23:50:27 BST 2005
Robey Pointer wrote:
>
> On 18 Oct 2005, at 23:17, Aaron Bentley wrote:
>
>>>> Yuck. :( My coworkershave been known to checkin 100+MB tarballs,
>>>> and you don't want to load that all into memory at once.
>>>
>>>
>>> We already do. Look at osutils.pumpfile.
>
>
> Ouch! Well just to prove that I'm not always just sniping from the
> sidelines, here's a small patch to fix that one. :)
>
> robey
>
What is wrong with:
chunk = file.read(blocksize)
while chunk:
tofile.write(chunk)
chunk = file.read(blocksize)
I realize generators are spiffy, it just seems like overkill. (though
filereader() might be generally useful)
John
=:->
>
> === modified file 'bzrlib/osutils.py'
> --- bzrlib/osutils.py
> +++ bzrlib/osutils.py
> @@ -224,9 +224,16 @@
> return False
>
>
> +def filereader(f, blocksize=128*1024):
> + x = f.read(blocksize)
> + while x != '':
> + yield x
> + x = f.read(blocksize)
> +
> def pumpfile(fromfile, tofile):
> """Copy contents of one file to another."""
> - tofile.write(fromfile.read())
> + for block in filereader(fromfile):
> + tofile.write(block)
>
>
> def sha_file(f):
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051019/55b416b3/attachment.pgp
More information about the bazaar
mailing list