Skip to content

Latest commit

 

History

History
491 lines (179 loc) · 5.02 KB

AppendStream.md

File metadata and controls

491 lines (179 loc) · 5.02 KB

AppendStream

Reads from multiple streams, one after the other.

This is a read-only stream decorator.

  • Full name: \GuzzleHttp\Psr7\AppendStream
  • This class is marked as final and can't be subclassed
  • This class implements: \Psr\Http\Message\StreamInterface
  • This class is a Final class

Properties

streams

private \Psr\Http\Message\StreamInterface[] $streams

seekable

private bool $seekable

current

private int $current

pos

private int $pos

Methods

__construct

public __construct(\Psr\Http\Message\StreamInterface[] $streams = []): mixed

Parameters:

Parameter Type Description
$streams \Psr\Http\Message\StreamInterface[] Streams to decorate. Each stream must
be readable.

__toString

Reads all data from the stream into a string, from the beginning to end.

public __toString(): string

This method MUST attempt to seek to the beginning of the stream before reading data and read the stream until the end is reached.

Warning: This could attempt to load a large amount of data into memory.

This method MUST NOT raise an exception in order to conform with PHP's string casting operations.


addStream

Add a stream to the AppendStream

public addStream(\Psr\Http\Message\StreamInterface $stream): void

Parameters:

Parameter Type Description
$stream \Psr\Http\Message\StreamInterface Stream to append. Must be readable.

getContents

Returns the remaining contents in a string

public getContents(): string

close

Closes each attached stream.

public close(): void

detach

Detaches each attached stream.

public detach(): resource|null

Returns null as it's not clear which underlying stream resource to return.

Return Value:

Underlying PHP stream, if any


tell

Returns the current position of the file read/write pointer

public tell(): int

Return Value:

Position of the file pointer


getSize

Tries to calculate the size by adding the size of each stream.

public getSize(): int|null

If any of the streams do not return a valid number, then the size of the append stream cannot be determined and null is returned.

Return Value:

Returns the size in bytes if known, or null if unknown.


eof

Returns true if the stream is at the end of the stream.

public eof(): bool

rewind

Seek to the beginning of the stream.

public rewind(): void

If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).


seek

Attempts to seek to the given position. Only supports SEEK_SET.

public seek(mixed $offset, mixed $whence = SEEK_SET): void

Parameters:

Parameter Type Description
$offset mixed Stream offset
$whence mixed Specifies how the cursor position will be calculated
based on the seek offset. Valid values are identical to the built-in
PHP $whence values for fseek(). SEEK_SET: Set position equal to
offset bytes SEEK_CUR: Set position to current location plus offset
SEEK_END: Set position to end-of-stream plus offset.

read

Reads from all of the appended streams until the length is met or EOF.

public read(mixed $length): string

Parameters:

Parameter Type Description
$length mixed Read up to $length bytes from the object and return
them. Fewer than $length bytes may be returned if underlying stream
call returns fewer bytes.

Return Value:

Returns the data read from the stream, or an empty string if no bytes are available.


isReadable

Returns whether or not the stream is readable.

public isReadable(): bool

isWritable

Returns whether or not the stream is writable.

public isWritable(): bool

isSeekable

Returns whether or not the stream is seekable.

public isSeekable(): bool

write

Write data to the stream.

public write(mixed $string): int

Parameters:

Parameter Type Description
$string mixed The string that is to be written.

Return Value:

Returns the number of bytes written to the stream.


getMetadata

Get stream metadata as an associative array or retrieve a specific key.

public getMetadata(mixed $key = null): mixed

Parameters:

Parameter Type Description
$key mixed Specific metadata to retrieve.