Commit efd4a76d authored by Łukasz Nowak's avatar Łukasz Nowak

Minimise memory footprint during download.

There is no need to read and store downloaded file. Returning the location is
good enough.
parent d629e039
0.2 (unreleased) 0.2 (unreleased)
================ ================
* Incompatible change: NetworkcacheClient.download returns downloaded
location instead of content in order to minimise memory footprint. [Łukasz
Nowak]
* Minimise memory footprint during upload. [Łukasz Nowak] * Minimise memory footprint during upload. [Łukasz Nowak]
* Use PUT instead of POST during upload. [Lucas Carvalho] * Use PUT instead of POST during upload. [Lucas Carvalho]
......
...@@ -18,7 +18,6 @@ import hashlib ...@@ -18,7 +18,6 @@ import hashlib
import httplib import httplib
import json import json
import os import os
import tempfile
from urllib import urlretrieve from urllib import urlretrieve
from urlparse import urlparse from urlparse import urlparse
...@@ -130,16 +129,11 @@ class NetworkcacheClient(object): ...@@ -130,16 +129,11 @@ class NetworkcacheClient(object):
def download(self, sha512sum): def download(self, sha512sum):
''' Download the file. ''' Download the file.
It uses http GET request method. It uses http GET request method.
Returns downloaded file absolute location
''' '''
sha_cache_url = os.path.join(self.shacache_url, sha512sum) sha_cache_url = os.path.join(self.shacache_url, sha512sum)
path, headers = urlretrieve(sha_cache_url, tempfile.mktemp()) path, headers = urlretrieve(sha_cache_url)
f = open(path) return path
try:
file_content = f.read()
finally:
f.close()
return file_content
def select(self, directory_key=None): def select(self, directory_key=None):
''' Download a file from shacache by selecting the entry in shadir ''' 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