mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 10:59:02 +01:00
Add downloadToReturnedStream method
This commit is contained in:
parent
7da7e5215a
commit
df1e6b2ba8
@ -204,6 +204,12 @@
|
||||
<code>$cacheTtl</code>
|
||||
</PropertyNotSetInConstructor>
|
||||
</file>
|
||||
<file src="src/Db/CachedArray.php">
|
||||
<LessSpecificImplementedReturnType>
|
||||
<code>Traversable</code>
|
||||
<code>Traversable</code>
|
||||
</LessSpecificImplementedReturnType>
|
||||
</file>
|
||||
<file src="src/Db/DbArrayTrait.php">
|
||||
<InvalidArgument>
|
||||
<code>$index</code>
|
||||
@ -244,6 +250,9 @@
|
||||
<code>$settings</code>
|
||||
<code>$settings</code>
|
||||
</ArgumentTypeCoercion>
|
||||
<MethodSignatureMismatch>
|
||||
<code>DriverArray</code>
|
||||
</MethodSignatureMismatch>
|
||||
<MissingClosureParamType>
|
||||
<code>$v</code>
|
||||
<code>$value</code>
|
||||
|
@ -16,13 +16,11 @@
|
||||
|
||||
namespace danog\MadelineProto\Db;
|
||||
|
||||
use Closure;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\Magic;
|
||||
use danog\MadelineProto\Settings\Database\DriverDatabaseAbstract;
|
||||
use danog\MadelineProto\Settings\Database\SerializerType;
|
||||
use danog\MadelineProto\Settings\DatabaseAbstract;
|
||||
use Exception;
|
||||
use IteratorAggregate;
|
||||
|
||||
use function Amp\async;
|
||||
|
@ -446,6 +446,18 @@ abstract class InternalDoc
|
||||
{
|
||||
return $this->wrapper->getAPI()->downloadToResponse($messageMedia, $request, $cb, $size, $mime, $name);
|
||||
}
|
||||
/**
|
||||
* Download file to an amphp stream, returning it.
|
||||
*
|
||||
* @param mixed $messageMedia File to download
|
||||
* @param callable $cb Callback
|
||||
* @param int $offset Offset where to start downloading
|
||||
* @param int $end Offset where to end download
|
||||
*/
|
||||
public function downloadToReturnedStream(mixed $messageMedia, ?callable $cb = null, int $offset = 0, int $end = -1): \Amp\ByteStream\ReadableStream
|
||||
{
|
||||
return $this->wrapper->getAPI()->downloadToReturnedStream($messageMedia, $cb, $offset, $end);
|
||||
}
|
||||
/**
|
||||
* Download file to stream.
|
||||
*
|
||||
|
@ -124,6 +124,27 @@ trait FilesLogic
|
||||
$this->downloadToStream($messageMedia, \fopen('php://output', 'w'), $cb, ...$result->getServeRange());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Download file to an amphp stream, returning it.
|
||||
*
|
||||
* @param mixed $messageMedia File to download
|
||||
* @param callable $cb Callback
|
||||
* @param int $offset Offset where to start downloading
|
||||
* @param int $end Offset where to end download
|
||||
*/
|
||||
public function downloadToReturnedStream(mixed $messageMedia, ?callable $cb = null, int $offset = 0, int $end = -1): ReadableStream
|
||||
{
|
||||
$pipe = new Pipe(1024*1024);
|
||||
$sink = $pipe->getSink();
|
||||
EventLoop::queue(function () use ($messageMedia, $sink, $cb, $offset, $end): void {
|
||||
try {
|
||||
$this->downloadToStream($messageMedia, $sink, $cb, $offset, $end);
|
||||
} finally {
|
||||
$sink->close();
|
||||
}
|
||||
});
|
||||
return $pipe->getSource();
|
||||
}
|
||||
/**
|
||||
* Download file to stream.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user