-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] introduction of interface IChunkHandler and a very first stupid implemen... #12160
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1bee33e
introduction of interface IChunkHandler and a very first stupid imple…
DeepDiver1975 33fd130
adding unit tests for file chunking
DeepDiver1975 754cae8
Remove unused file_assemble
DeepDiver1975 174b14a
adding hook processing to chunked file upload
DeepDiver1975 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,70 @@ | ||
<?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; | ||
|
||
private $cache; | ||
|
||
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, $this->cache); | ||
$bytesWritten = $chunkHandler->store($index, $data); | ||
if ($bytesWritten != $chunkSize) { | ||
$chunkHandler->remove($index); | ||
} | ||
$complete = false; | ||
$actualSize = $chunkHandler->getCurrentSize(); | ||
|
||
if ($chunkHandler->isComplete()) { | ||
$complete = true; | ||
$f = $this->storage->fopen("/files" . $fileName, 'w'); | ||
$chunkHandler->assemble($f); | ||
fclose($f); | ||
} | ||
|
||
return array( | ||
'complete' => $complete, | ||
'bytesWritten' => $bytesWritten, | ||
'actualSize' => $actualSize | ||
); | ||
} | ||
|
||
public function setFileCache($cache) { | ||
$this->cache = $cache; | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so the last chunk would trigger assembling.
I'm not sure, I'd have moved this to a separate function but am not sure why. Maybe to give the caller more control of when they want to do the assembling.
If you decide to keep it this way, it might be a good idea to at least expose
isComplete()
on the interface.