diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-07-27 19:02:23 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-07-27 19:35:33 +0200 |
commit | 896d27de36dd26515f30fa3b0748c9c6089600af (patch) | |
tree | 93aab8d29799875faf98f244ddcca77155e0012b /lib/filechunking.php | |
parent | 1ea33ff36bf70ee2099f8d225f488dc220e3bcff (diff) | |
download | nextcloud-server-896d27de36dd26515f30fa3b0748c9c6089600af.tar.gz nextcloud-server-896d27de36dd26515f30fa3b0748c9c6089600af.zip |
Chunked upload: Support reusing local chunks
Diffstat (limited to 'lib/filechunking.php')
-rw-r--r-- | lib/filechunking.php | 32 |
1 files changed, 30 insertions, 2 deletions
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, + ); + } } |