下载后如何检查.tar.gz存档是否已损坏?

时间:2016-07-12 11:23:25

标签: python-2.7 download python-requests archive gz

我使用python 2.7.8并请求库从USGS.gov网站下载tar.gz档案。

数据示例: http://dds.cr.usgs.gov/ltaauth//data/standard_l1t/etm/29/30/2016/LE70290302016178EDC00.tar.gz?id=48aq2ki3sr01iq18pdo8jdmi47&iid=LE70290302016178EDC00&did=252710635&ver=production

有时我的连接被中断,并且所有文件都没有从存档中正确解压缩(但文件没有完全损坏)。我使用以下代码(其中一部分)来下载数据:

import requests
import traceback

def download_file(url, file_path):
    # NOTE the stream=True parameter
    r = requests.get(url, timeout=120, stream=True)
    with open(file_path, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024): 
            if chunk:
                f.write(chunk)    
    return file_path

try:
    download_file(URL, scene_path)    
except:
    traceback.print_exc() 
    if os.path.isfile(scene_path):
        os.remove(scene_path)
        print u'<= DEL'

如何检查下载后* .tar.gz存档是否已损坏?

0 个答案:

没有答案
相关问题