Commit 27cdcb1c authored by Lucas Carvalho's avatar Lucas Carvalho

The download method must return a file descriptor.

It should return the file descriptor instead of file content as string.

This implementation does not consume RAM Memory, so it is safer to
download big files.

When you call file_descriptor.close, it will remove the file from tmp
folder automatically.
parent efd4a76d
......@@ -18,6 +18,7 @@ import hashlib
import httplib
import json
import os
import tempfile
from urllib import urlretrieve
from urlparse import urlparse
......@@ -129,11 +130,12 @@ class NetworkcacheClient(object):
def download(self, sha512sum):
''' Download the file.
It uses http GET request method.
Returns downloaded file absolute location
'''
sha_cache_url = os.path.join(self.shacache_url, sha512sum)
path, headers = urlretrieve(sha_cache_url)
return path
file_descriptor = tempfile.NamedTemporaryFile()
path, headers = urlretrieve(sha_cache_url, file_descriptor.name)
file_descriptor.seek(0)
return file_descriptor
def select(self, directory_key=None):
''' Download a file from shacache by selecting the entry in shadir
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment