]> source.dussan.org Git - nextcloud-server.git/commitdiff
returning the number of stored bytes in store() and adding cleanup() method
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 16 Sep 2013 08:47:29 +0000 (10:47 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Mon, 16 Sep 2013 08:47:29 +0000 (10:47 +0200)
lib/filechunking.php

index e6d69273a44a6e08e4ad1bcf728c6cea78808ea2..c0e3acbf1aa9985e1260771155347cffe22b635c 100644 (file)
@@ -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];