1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-26 20:04:51 +01:00

Update for async-interop merge and other Amp changes; changed namespace to ByteStream

This commit is contained in:
Aaron Piotrowski 2017-03-16 10:22:32 -05:00
parent 4c5b7f539b
commit 4414c6bbe4
8 changed files with 23 additions and 26 deletions

View File

@ -24,13 +24,12 @@
"amphp/amp": "dev-master as 2.0"
},
"require-dev": {
"amphp/loop": "dev-master",
"phpunit/phpunit": "^5",
"friendsofphp/php-cs-fixer": "~1.9"
},
"autoload": {
"psr-4": {
"Amp\\Stream\\": "lib/"
"Amp\\ByteStream\\": "lib/"
},
"files": [
"lib/functions.php",
@ -39,7 +38,7 @@
},
"autoload-dev": {
"psr-4": {
"Amp\\Stream\\Test\\": "test/"
"Amp\\ByteStream\\Test\\": "test/"
}
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Amp\Stream;
namespace Amp\ByteStream;
/**
*/

View File

@ -1,18 +1,18 @@
<?php
namespace Amp\Stream;
namespace Amp\ByteStream;
/**
*/
class BufferIterator implements \SeekableIterator {
/** @var \Amp\Stream\Buffer */
/** @var \Amp\ByteStream\Buffer */
private $buffer;
/** @var int */
private $current = 0;
/**
* @param \Amp\Stream\Buffer $buffer
* @param \Amp\ByteStream\Buffer $buffer
*/
public function __construct(Buffer $buffer) {
$this->buffer = $buffer;

View File

@ -1,8 +1,8 @@
<?php
namespace Amp\Stream;
namespace Amp\ByteStream;
use AsyncInterop\Promise;
use Amp\Promise;
interface ByteStream {
/**
@ -23,21 +23,21 @@ interface ByteStream {
* @param int|null $bytes
* @param string|null $delimiter
*
* @return \AsyncInterop\Promise<string> Resolves with bytes read from the stream.
* @return \Amp\Promise<string> Resolves with bytes read from the stream.
*/
public function read(int $bytes = null, string $delimiter = null): Promise;
/**
* @param string $data
*
* @return \AsyncInterop\Promise<int>
* @return \Amp\Promise<int>
*/
public function write(string $data): Promise;
/**
* @param string $data
*
* @return \AsyncInterop\Promise<int>
* @return \Amp\Promise<int>
*/
public function end(string $data = ''): Promise;

View File

@ -1,5 +1,5 @@
<?php
namespace Amp\Stream;
namespace Amp\ByteStream;
class ClosedException extends \Exception {}

View File

@ -1,8 +1,8 @@
<?php
namespace Amp\Stream\Internal;
namespace Amp\ByteStream\Internal;
use Amp\Stream\ByteStream;
use Amp\ByteStream\ByteStream;
/**
* @internal

View File

@ -1,9 +1,8 @@
<?php
namespace Amp\Stream;
namespace Amp\ByteStream;
use Amp\{ Deferred, Failure, Success };
use AsyncInterop\Promise;
use Amp\{ Deferred, Failure, Promise, Success };
/**
* Serves as buffer that implements the stream interface, allowing consumers to be notified when data is available in
@ -11,7 +10,7 @@ use AsyncInterop\Promise;
* or writing, as well as acting as an example of how stream classes can be implemented.
*/
class MemoryStream implements ByteStream {
/** @var \Amp\Stream\Buffer */
/** @var \Amp\ByteStream\Buffer */
private $buffer;
/** @var bool */
@ -139,7 +138,7 @@ class MemoryStream implements ByteStream {
* @param string $data
* @param bool $end
*
* @return \AsyncInterop\Promise
* @return \Amp\Promise
*/
protected function send(string $data, bool $end = false): Promise {
if (!$this->writable) {

View File

@ -1,9 +1,8 @@
<?php
namespace Amp\Stream;
namespace Amp\ByteStream;
use Amp\Coroutine;
use AsyncInterop\Promise;
use Amp\{ Coroutine, Promise };
// @codeCoverageIgnoreStart
if (\strlen('…') !== 3) {
@ -13,11 +12,11 @@ if (\strlen('…') !== 3) {
} // @codeCoverageIgnoreEnd
/**
* @param \Amp\Stream\ByteStream $source
* @param \Amp\Stream\ByteStream $destination
* @param \Amp\ByteStream\ByteStream $source
* @param \Amp\ByteStream\ByteStream $destination
* @param int|null $bytes
*
* @return \AsyncInterop\Promise
* @return \Amp\Promise
*/
function pipe(ByteStream $source, ByteStream $destination, int $bytes = null): Promise {
return new Coroutine(Internal\pipe($source, $destination, $bytes));