diff --git a/src/danog/MadelineProto/MTProtoTools/Files.php b/src/danog/MadelineProto/MTProtoTools/Files.php index 2eaedfef..944b5220 100644 --- a/src/danog/MadelineProto/MTProtoTools/Files.php +++ b/src/danog/MadelineProto/MTProtoTools/Files.php @@ -353,8 +353,11 @@ trait Files }; } $message_media = $this->get_download_info($message_media); - if (stream_get_meta_data($stream)['seekable']) { - fseek($stream, $offset); + try { + if (stream_get_meta_data($stream)['seekable']) { + fseek($stream, $offset); + } + } catch (\danog\MadelineProto\Exception $e) { } $downloaded_size = 0; if ($end === -1 && isset($message_media['size'])) { diff --git a/src/danog/MadelineProto/Server/Stream.php b/src/danog/MadelineProto/Server/Stream.php index 34192213..410c9cee 100644 --- a/src/danog/MadelineProto/Server/Stream.php +++ b/src/danog/MadelineProto/Server/Stream.php @@ -30,17 +30,17 @@ class Stream self::$_isRegistered = true; } - return stream_context_create([self::WRAPPER_NAME => ['handler' => $handler, $stream_id]]); + return stream_context_create([self::WRAPPER_NAME => ['handler' => $handler, 'stream_id' => $stream_id]]); } public function stream_open($path, $mode, $options, &$opened_path) { $opt = stream_context_get_options($this->context); + if (!is_array($opt[self::WRAPPER_NAME]) || !isset($opt[self::WRAPPER_NAME]['handler']) || !($opt[self::WRAPPER_NAME]['handler'] instanceof Handler) || - !isset($opt[self::WRAPPER_NAME]['stream_id']) || - !is_int($opt[self::WRAPPER_NAME]['stream_id'])) { + !isset($opt[self::WRAPPER_NAME]['stream_id'])) { return false; } $this->_handler = $opt[self::WRAPPER_NAME]['handler']; @@ -51,7 +51,7 @@ class Stream public function stream_write($data) { - $this->handler->send_data($this->_stream_id, $data); + $this->_handler->send_data($this->_stream_id, $data); } public function stream_lock($mode) diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index c94364ad..da3a9922 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -282,6 +282,7 @@ trait TL return $concat; case 'bytes': + if (is_array($object) && isset($object['_']) && $object['_'] === 'bytes') $object = base64_decode($object['bytes']); if (!is_string($object) && !$object instanceof \danog\MadelineProto\TL\Types\Bytes) { throw new Exception("You didn't provide a valid string"); } diff --git a/src/danog/MadelineProto/TL/Types/Bytes.php b/src/danog/MadelineProto/TL/Types/Bytes.php index 436495f5..34c70de4 100644 --- a/src/danog/MadelineProto/TL/Types/Bytes.php +++ b/src/danog/MadelineProto/TL/Types/Bytes.php @@ -35,6 +35,6 @@ class Bytes extends \Volatile implements \JsonSerializable public function jsonSerialize() { - return utf8_encode($this->bytes); + return ['_' => 'bytes', 'bytes' => base64_encode($this->bytes)]; } } diff --git a/src/danog/MadelineProto/TL_socket.tl b/src/danog/MadelineProto/TL_socket.tl index 8d757bdc..e31e46ac 100644 --- a/src/danog/MadelineProto/TL_socket.tl +++ b/src/danog/MadelineProto/TL_socket.tl @@ -5,7 +5,7 @@ socketMessageResponse request_id:int data:%DataJSON = SocketMessage; socketMessageException request_id:int exception:SocketException = SocketMessage; socketMessageUpdate data:%DataJSON = SocketMessage; socketMessageLog flags:# thread:flags.0?true process:flags.1?true file:string level:int data:%DataJSON = SocketMessage; -socketMessageRawData stream_id:int data:bytes = SocketMessage; +socketMessageRawData stream_id:string data:bytes = SocketMessage; socketException message:string code:int trace:%SocketTLTrace = SocketException; socketRPCErrorException flags:# rpc_message:flags.0?string message:flags.1?string code:int trace:%SocketTLTrace = SocketException;