[PATCH] Do not read file to memory on commit

Fredrik Lundh fredrik at pythonware.com
Sat Apr 16 23:25:10 BST 2005


Harri Salokorpi wrote:

> +def file_size(f):
> +    if not isfile(f):
> +        raise BzrError( "attempted to get file size for non-file (%r)" % ( file_kind(f) ) )
> +    return os.lstat(f)[ST_SIZE]

why os.lstat instead of os.stat (or os.path.getsize)?

also note that if you have an opened file (like in this case), doing

    try:
        st = os.fstat(file.fileno())
    except AttributeError:
        st = os.stat(filename)
    size = st[ST_SIZE]

might be faster (but someone should benchmark this)

</F>





More information about the bazaar mailing list