Skip to content

Latest commit

 

History

History
720 lines (238 loc) · 5.82 KB

CachingStream.md

File metadata and controls

720 lines (238 loc) · 5.82 KB

CachingStream

Stream decorator that can cache previously read bytes from a sequentially read stream.

  • Full name: \GuzzleHttp\Psr7\CachingStream
  • 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

remoteStream

private \Psr\Http\Message\StreamInterface $remoteStream

skipReadBytes

private int $skipReadBytes

stream

private \Psr\Http\Message\StreamInterface $stream

Methods

__construct

We will treat the buffer object as the body of the stream

public __construct(\Psr\Http\Message\StreamInterface $stream, \Psr\Http\Message\StreamInterface $target = null): mixed

Parameters:

Parameter Type Description
$stream \Psr\Http\Message\StreamInterface Stream to cache. The cursor is assumed to be at the beginning of the stream.
$target \Psr\Http\Message\StreamInterface Optionally specify where data is cached

getSize

Get the size of the stream if known.

public getSize(): int|null

Return Value:

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


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

Seek to a position in the stream.

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

Read data from the stream.

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.


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.


eof

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

public eof(): bool

close

Close both the remote stream and buffer stream

public close(): void

cacheEntireStream

private cacheEntireStream(): int

Inherited methods

__construct

public __construct(\Psr\Http\Message\StreamInterface $stream): mixed

Parameters:

Parameter Type Description
$stream \Psr\Http\Message\StreamInterface Stream to decorate

__get

Magic method used to create a new stream if streams are not added in the constructor of a decorator (e.g., LazyOpenStream).

public __get(string $name): \Psr\Http\Message\StreamInterface

Parameters:

Parameter Type Description
$name string

__toString

public __toString(): string

getContents

public getContents(): string

__call

Allow decorators to implement custom methods

public __call(string $method, array $args): mixed

Parameters:

Parameter Type Description
$method string
$args array

close

public close(): void

getMetadata

{@inheritdoc}

public getMetadata(mixed $key = null): mixed

Parameters:

Parameter Type Description
$key mixed

detach

public detach(): mixed

getSize

public getSize(): ?int

eof

public eof(): bool

tell

public tell(): int

isReadable

public isReadable(): bool

isWritable

public isWritable(): bool

isSeekable

public isSeekable(): bool

rewind

public rewind(): void

seek

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

Parameters:

Parameter Type Description
$offset mixed
$whence mixed

read

public read(mixed $length): string

Parameters:

Parameter Type Description
$length mixed

write

public write(mixed $string): int

Parameters:

Parameter Type Description
$string mixed

createStream

Implement in subclasses to dynamically create streams when requested.

protected createStream(): \Psr\Http\Message\StreamInterface