Skip to content
Snippets Groups Projects
Commit f7d41c8a authored by John Chilton's avatar John Chilton
Browse files

Merge pull request #71 from natefoo/pycurl_resume

Support for resuming staging transfers
parents 2b3942db 0c61bd96
No related branches found
No related tags found
No related merge requests found
...@@ -66,10 +66,18 @@ def post_file(url, path): ...@@ -66,10 +66,18 @@ def post_file(url, path):
def get_file(url, path): def get_file(url, path):
if path and os.path.exists(path):
buf = _open_output(path, 'ab')
size = os.path.getsize(path)
else:
buf = _open_output(path)
size = 0
buf = _open_output(path) buf = _open_output(path)
try: try:
c = _new_curl_object_for_url(url) c = _new_curl_object_for_url(url)
c.setopt(c.WRITEFUNCTION, buf.write) c.setopt(c.WRITEFUNCTION, buf.write)
if size > 0:
c.setopt(c.RESUME_FROM, size)
c.perform() c.perform()
status_code = c.getinfo(HTTP_CODE) status_code = c.getinfo(HTTP_CODE)
if int(status_code) != 200: if int(status_code) != 200:
...@@ -79,8 +87,8 @@ def get_file(url, path): ...@@ -79,8 +87,8 @@ def get_file(url, path):
buf.close() buf.close()
def _open_output(output_path): def _open_output(output_path, mode='wb'):
return open(output_path, 'wb') if output_path else BytesIO() return open(output_path, mode) if output_path else BytesIO()
def _new_curl_object_for_url(url): def _new_curl_object_for_url(url):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment