diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-09-16 10:47:29 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-14 15:42:53 +0200 |
commit | 73570d497960e5b01fda530d4cc1573c879aa3c7 (patch) | |
tree | 87ba7634410be11bdf125c2b370ce6a319eae234 | |
parent | 0ac379f9164ebfca15ec59be06ce88e242420ff4 (diff) | |
download | nextcloud-server-73570d497960e5b01fda530d4cc1573c879aa3c7.tar.gz nextcloud-server-73570d497960e5b01fda530d4cc1573c879aa3c7.zip |
returning the number of stored bytes in store() and adding cleanup() method
-rw-r--r-- | lib/filechunking.php | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/filechunking.php b/lib/filechunking.php index e6d69273a44..c0e3acbf1aa 100644 --- a/lib/filechunking.php +++ b/lib/filechunking.php @@ -34,10 +34,19 @@ class OC_FileChunking { return $this->cache; } + /** + * Stores the given $data under the given $key - the number of stored bytes is returned + * + * @param $index + * @param $data + * @return int + */ public function store($index, $data) { $cache = $this->getCache(); $name = $this->getPrefix().$index; $cache->set($name, $data); + + return $cache->size($name); } public function isComplete() { @@ -58,12 +67,24 @@ class OC_FileChunking { $count = 0; for($i=0; $i < $this->info['chunkcount']; $i++) { $chunk = $cache->get($prefix.$i); - $cache->remove($prefix.$i); $count += fwrite($f, $chunk); } + + $this->cleanup(); return $count; } + /** + * Removes all chunks which belong to this transmission + */ + public function cleanup() { + $cache = $this->getCache(); + $prefix = $this->getPrefix(); + for($i=0; $i < $this->info['chunkcount']; $i++) { + $cache->remove($prefix.$i); + } + } + public function signature_split($orgfile, $input) { $info = unpack('n', fread($input, 2)); $blocksize = $info[1]; |