2016-12-30 06:09:06 +01:00
|
|
|
<?php
|
2016-08-16 23:23:46 +02:00
|
|
|
|
2016-08-10 23:48:42 +02:00
|
|
|
namespace Amp\Stream;
|
|
|
|
|
2017-01-09 17:29:08 +01:00
|
|
|
use AsyncInterop\Promise;
|
2016-08-16 00:19:32 +02:00
|
|
|
|
2017-01-09 17:52:29 +01:00
|
|
|
interface ByteStream {
|
2016-08-10 23:48:42 +02:00
|
|
|
/**
|
|
|
|
* Determines if the stream is readable.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2016-08-16 00:19:32 +02:00
|
|
|
public function isReadable(): bool;
|
2016-08-10 23:48:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the stream is writable.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2016-08-16 00:19:32 +02:00
|
|
|
public function isWritable(): bool;
|
2016-08-10 23:48:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int|null $bytes
|
|
|
|
* @param string|null $delimiter
|
|
|
|
*
|
2017-01-09 17:29:08 +01:00
|
|
|
* @return \AsyncInterop\Promise<string> Resolves with bytes read from the stream.
|
2016-08-10 23:48:42 +02:00
|
|
|
*/
|
2016-11-14 22:05:19 +01:00
|
|
|
public function read(int $bytes = null, string $delimiter = null): Promise;
|
2016-08-10 23:48:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $data
|
|
|
|
*
|
2017-01-09 17:29:08 +01:00
|
|
|
* @return \AsyncInterop\Promise<int>
|
2016-08-10 23:48:42 +02:00
|
|
|
*/
|
2016-11-14 22:05:19 +01:00
|
|
|
public function write(string $data): Promise;
|
2016-08-10 23:48:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $data
|
|
|
|
*
|
2017-01-09 17:29:08 +01:00
|
|
|
* @return \AsyncInterop\Promise<int>
|
2016-08-10 23:48:42 +02:00
|
|
|
*/
|
2016-11-14 22:05:19 +01:00
|
|
|
public function end(string $data = ''): Promise;
|
2016-08-10 23:48:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes the stream and fails any pending reads or writes.
|
|
|
|
*/
|
|
|
|
public function close();
|
|
|
|
}
|