2010-06-12 3 views
2

RESUME_FROM 옵션이 작동하지 않는 것 같습니다.PycURL RESUME_FROM

import os 
import pycurl 
import sys 

def progress(total, existing, upload_t, upload_d): 
    try: 
     frac = float(existing)/float(total) 
    except: 
     frac = 0 
    sys.stdout.write("\r%s %3i%%" % ("file", frac*100) ) 

url = "http://launchpad.net/keryx/stable/0.92/+download/keryx_0.92.4.tar.gz" 
filename = url.split("/")[-1].strip() 

def test(debug_type, debug_msg): 
    print "debug(%d): %s" % (debug_type, debug_msg) 

c = pycurl.Curl() 
c.setopt(pycurl.URL, url) 
c.setopt(pycurl.FOLLOWLOCATION, 1) 
c.setopt(pycurl.MAXREDIRS, 5) 

# Setup writing 
if os.path.exists(filename): 
    f = open(filename, "ab") 
    c.setopt(pycurl.RESUME_FROM, os.path.getsize(filename)) 
else: 
    f = open(filename, "wb") 
c.setopt(pycurl.WRITEDATA, f) 

#c.setopt(pycurl.VERBOSE, 1) 
c.setopt(pycurl.DEBUGFUNCTION, test) 
c.setopt(pycurl.NOPROGRESS, 0) 
c.setopt(pycurl.PROGRESSFUNCTION, progress) 
c.perform() 

답변

3
그것은 실제로 제대로 다시 시작되었다

그러나 그것은 다시 시작하는 것은 os.path.getsize (파일 이름)의 길이에 추가되지 않았기 때문에 시작 될 듯 : 여기에 테스트 된 몇 가지 예제 코드는 진행 기능에 존재합니다. 사소한 실수! :)

관련 문제