Commit 24f92f40 authored by Łukasz Nowak's avatar Łukasz Nowak

Minimise memory footprint during upload.

There is no need to read whole file into memory on library level. So calculate
sum in chunks and give request method file descriptor.
parent 81e88815
......@@ -68,14 +68,21 @@ class NetworkcacheClient(object):
msg = 'The parameter "urlmd5" is required once you set directory_key.'
raise ValueError(msg)
file_content =
sha512sum = hashlib.sha512(file_content).hexdigest()
path = os.path.join(self.shacache_path, sha512sum)
sha512sum = hashlib.sha512()
# do not trust, go to beginning of opened file
while True:
d =
if not d:
path = os.path.join(self.shacache_path, sha512sum.hexdigest())
shacache_connection = httplib.HTTPConnection(self.shacache_host,
shacache_connection.request('PUT', path, file_content,
shacache_connection.request('PUT', path, file_descriptor,
result = shacache_connection.getresponse()
data =
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