From 896d27de36dd26515f30fa3b0748c9c6089600af Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 27 Jul 2012 19:02:23 +0200 Subject: Chunked upload: Support reusing local chunks --- lib/filechunking.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'lib/filechunking.php') diff --git a/lib/filechunking.php b/lib/filechunking.php index 9aead4c12fb..d03af226d8b 100644 --- a/lib/filechunking.php +++ b/lib/filechunking.php @@ -23,9 +23,8 @@ class OC_FileChunking { public function getPrefix() { $name = $this->info['name']; $transferid = $this->info['transferid']; - $chunkcount = $this->info['chunkcount']; - return $name.'-chunking-'.$transferid.'-'.$chunkcount.'-'; + return $name.'-chunking-'.$transferid.'-'; } protected function getCache() { @@ -63,4 +62,33 @@ class OC_FileChunking { } fclose($f); } + + public function signature_split($orgfile, $input) { + $info = unpack('n', fread($input, 2)); + $blocksize = $info[1]; + $this->info['transferid'] = mt_rand(); + $count = 0; + $needed = array(); + $cache = $this->getCache(); + $prefix = $this->getPrefix(); + while (!feof($orgfile)) { + $new_md5 = fread($input, 16); + if (feof($input)) { + break; + } + $data = fread($orgfile, $blocksize); + $org_md5 = md5($data, true); + if ($org_md5 == $new_md5) { + $cache->set($prefix.$count, $data); + } else { + $needed[] = $count; + } + $count++; + } + return array( + 'transferid' => $this->info['transferid'], + 'needed' => $needed, + 'count' => $count, + ); + } } -- cgit v1.2.3