Add rename tests

This commit is contained in:
Daniil Gentili 2019-12-30 00:22:01 +01:00
parent d3f0889e56
commit 62dfaa0abe
3 changed files with 18 additions and 9 deletions

2
docs

@ -1 +1 @@
Subproject commit 7e995342fef7cb8f489d80983e9e7b34012b1a89 Subproject commit 4ed3a8447cf21c69322bcdaf149eb3ce0befe8c0

View File

@ -392,7 +392,7 @@ trait Files
$chunk_size = $this->settings['upload']['part_size']; $chunk_size = $this->settings['upload']['part_size'];
$bridge = new class($size, $chunk_size) { $bridge = new class($size, $chunk_size, $cb) {
/** /**
* Read promises. * Read promises.
* *
@ -417,20 +417,28 @@ trait Files
* @var int * @var int
*/ */
private $offset = 0; private $offset = 0;
/**
* Callback
*
* @var ?callable
*/
private $cb;
/** /**
* Constructor. * Constructor.
* *
* @param integer $size Total file size * @param integer $size Total file size
* @param integer $partSize Part size * @param integer $partSize Part size
* @param integer $cb Callback
*/ */
public function __construct(int $size, int $partSize) public function __construct(int $size, int $partSize, $cb)
{ {
for ($x = 0; $x < $size; $x += $partSize) { for ($x = 0; $x < $size; $x += $partSize) {
$this->read []= new Deferred; $this->read []= new Deferred;
$this->write []= new Deferred; $this->write []= new Deferred;
} }
$this->partSize = $partSize; $this->partSize = $partSize;
$this->cb = $cb;
} }
/** /**
* Read chunk. * Read chunk.
@ -467,15 +475,14 @@ trait Files
public function callback(): void public function callback(): void
{ {
$this->read[$this->offset++]->resolve(); $this->read[$this->offset++]->resolve();
if ($this->cb) {
Tools::callFork(($this->cb)());
}
} }
}; };
$reader = [$bridge, 'read']; $reader = [$bridge, 'read'];
$writer = [$bridge, 'write']; $writer = [$bridge, 'write'];
$cb = [$bridge, 'callback'];
$cb = static function (...$params) use ($cb, $bridge): \Generator {
$bridge->callback();
yield $cb(...$params);
};
$read = $this->uploadFromCallable($reader, $size, $mime, '', $cb, true, $encrypted); $read = $this->uploadFromCallable($reader, $size, $mime, '', $cb, true, $encrypted);
$write = $this->downloadToCallable($media, $writer, null, true, 0, -1, $chunk_size); $write = $this->downloadToCallable($media, $writer, null, true, 0, -1, $chunk_size);

View File

@ -273,7 +273,9 @@ var_dump(time()-$t);
foreach ($media as $type => $inputMedia) { foreach ($media as $type => $inputMedia) {
$MadelineProto->logger("Sending $type"); $MadelineProto->logger("Sending $type");
$type = yield $MadelineProto->messages->sendMedia(['peer' => $peer, 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown']); $type = yield $MadelineProto->messages->sendMedia(['peer' => $peer, 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown']);
yield $MadelineProto->downloadToDir(yield $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]), '/tmp'); yield $MadelineProto->downloadToDir($media = yield $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]), '/tmp');
$inputMedia['file'] = $media;
yield $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]);
} }
} }