-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduction of interface IChunkHandler and a very first stupid imple…
…mentation reusing the existing chunking mechanism
- Loading branch information
1 parent
5ca869c
commit a663692
Showing
7 changed files
with
147 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* @author Thomas Müller | ||
* @copyright 2014 Thomas Müller [email protected] | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
|
||
namespace OC\Files; | ||
|
||
use OCP\Files\Storage; | ||
|
||
class CachingChunkHandler implements \OCP\Files\IChunkHandler { | ||
|
||
/** | ||
* @var Storage | ||
*/ | ||
private $storage; | ||
|
||
public function __construct(Storage $storage) { | ||
$this->storage = $storage; | ||
} | ||
|
||
/** | ||
* Write a chunk to a give file. | ||
* | ||
* @param string $fileName | ||
* @param int $index | ||
* @param int $numberOfChunk | ||
* @param int $chunkSize | ||
* @param string $data | ||
* @return array | ||
*/ | ||
function storeChunk($fileName, $index, $numberOfChunk, $chunkSize, $data, $transferId) { | ||
$info = array( | ||
'name' => $transferId, | ||
'transferid' => $transferId, | ||
'chunkcount' => $numberOfChunk, | ||
'' | ||
); | ||
$chunkHandler = new \OC_FileChunking($info); | ||
$bytesWritten = $chunkHandler->store($index, $data); | ||
if ($bytesWritten != $chunkSize) { | ||
$chunkHandler->remove($index); | ||
} | ||
$complete = false; | ||
if ($chunkHandler->isComplete()) { | ||
$complete = true; | ||
$f = $this->storage->fopen("/files" . $fileName, 'w'); | ||
$chunkHandler->assemble($f); | ||
fclose($f); | ||
} | ||
|
||
return array( | ||
'complete' => $complete, | ||
'bytesWritten' => $bytesWritten, | ||
'actualSize' => $chunkHandler->getCurrentSize() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* @author Thomas Müller | ||
* @copyright 2014 Thomas Müller [email protected] | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
namespace OCP\Files; | ||
|
||
interface IChunkHandler { | ||
|
||
/** | ||
* Write a chunk to a give file. The returned array will holds following properties: | ||
* - bytesWritten - the number of bytes written with the current call | ||
* - complete - indicator if the file si complete and has been uploaded/stored in the storage, | ||
* - actualSize - current size of the file - equivalent to the sum of all stored chunks | ||
* | ||
* @param string $fileName | ||
* @param int $index | ||
* @param int $numberOfChunk | ||
* @param int $chunkSize the size of the current chunk | ||
* @param resource $data | ||
* @param string $transferId | ||
* @return array | ||
*/ | ||
public function storeChunk($fileName, $index, $numberOfChunk, $chunkSize, $data, $transferId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters