def test_read_long(r, inf):
    """Test read and readinto.
    """
    md_class = inf._md_class or rf.NoHashContext
    bctx = md_class()
    f = r.open(inf.filename)
    total = 0
    while 1:
        data = f.read(8192)
        if not data:
            break
        bctx.update(data)
        total += len(data)
    if total != inf.file_size:
        xprint("\n *** %s has corrupt file: %s ***", r.rarfile, inf.filename)
        xprint(" *** short read: got=%d, need=%d ***\n", total, inf.file_size)
    check_crc(f, inf, 'read')
    bhash = bctx.hexdigest()
    if cf_verbose > 1:
        if f._md_context.digest() == inf._md_expect:
            #xprint("  checkhash: %r", bhash)
            pass
        else:
            xprint("  checkhash: %r  got=%r exp=%r cls=%r\n",
                   bhash, f._md_context.digest(), inf._md_expect, inf._md_class)

    # test .seek() & .readinto()
    if cf_test_read > 1:
        f.seek(0, 0)

        total = 0
        buf = bytearray(rf.ZERO * 1024)
        while 1:
            res = f.readinto(buf)
            if not res:
                break
            total += res
        if inf.file_size != total:
            xprint(" *** readinto failed: got=%d, need=%d ***\n", total, inf.file_size)
        #check_crc(f, inf, 'readinto')
    f.close()
def test_read_long ( r , inf ) : md_class = inf . _md_class or rf . NoHashContext bctx = md_class ( ) f = r . open ( inf . filename ) total = 0 while 1 : data = f . read ( 8192 ) if not data : break bctx . update ( data ) total += len ( data ) if total != inf . file_size : xprint ( "\n *** %s has corrupt file: %s ***" , r . rarfile , inf . filename ) xprint ( " *** short read: got=%d, need=%d ***\n" , total , inf . file_size ) check_crc ( f , inf , 'read' ) bhash = bctx . hexdigest ( ) if cf_verbose > 1 : if f . _md_context . digest ( ) == inf . _md_expect : pass else : xprint ( "  checkhash: %r  got=%r exp=%r cls=%r\n" , bhash , f . _md_context . digest ( ) , inf . _md_expect , inf . _md_class ) if cf_test_read > 1 : f . seek ( 0 , 0 ) total = 0 buf = bytearray ( rf . ZERO * 1024 ) while 1 : res = f . readinto ( buf ) if not res : break total += res if inf . file_size != total : xprint ( " *** readinto failed: got=%d, need=%d ***\n" , total , inf . file_size ) f . close ( )
Test read and readinto.