2010-06-12 43 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(文件名)的长度没有添加到开始存在于进度功能中。只是一个小错误! :)