Kotchasan

Stream
in package
implements StreamInterface

PSR-7 compliant data stream class.

Represents a stream of data as defined by the PSR-7 StreamInterface.

Tags
see
https://www.kotchasan.com/

Interfaces, Classes and Traits

StreamInterface
Describes a data stream.

Table of Contents

$meta  : array<string|int, mixed>
Stream metadata.
$readable  : bool
Flag indicating if the stream is readable.
$seekable  : bool
Flag indicating if the stream is seekable.
$size  : null|int
Stream size.
$stream  : resource
Stream resource.
$writable  : bool
Flag indicating if the stream is writable.
__construct()  : mixed
Creates a new Stream instance.
__toString()  : string
Gets the contents of the stream as a string.
close()  : void
Closes the stream and releases its resources.
detach()  : resource|null
Detaches the stream resource and returns it.
eof()  : bool
Checks if the end of the stream has been reached.
getContents()  : string
Gets the contents of the stream as a string.
getMetadata()  : array<string|int, mixed>|mixed|null
Gets the metadata of the stream or a specific key of the metadata.
getSize()  : int|null
Gets the size of the stream in bytes.
isReadable()  : bool
Checks if the stream is readable.
isSeekable()  : bool
Checks if the stream is seekable.
isWritable()  : bool
Checks if the stream is writable.
read()  : string
Reads data from the stream.
rewind()  : mixed
Seeks to a specific position in the stream.
seek()  : mixed
เลื่อน pointer ไปยังตำแหน่งที่กำหนด
tell()  : int
คืนค่าตำแหน่งของ pointer ปัจจุบัน
write()  : int
เขียนข้อมูลลงบน stream คืนค่าจำนวน byte ที่เขียน

Properties

$meta

Stream metadata.

protected array<string|int, mixed> $meta

$readable

Flag indicating if the stream is readable.

protected bool $readable

$seekable

Flag indicating if the stream is seekable.

protected bool $seekable

$size

Stream size.

protected null|int $size

$stream

Stream resource.

protected resource $stream

$writable

Flag indicating if the stream is writable.

protected bool $writable

Methods

__construct()

Creates a new Stream instance.

public __construct(resource|string $stream[, string $mode = 'r' ]) : mixed
Parameters
$stream : resource|string

The stream resource or a string representing a file path or URL.

$mode : string = 'r'

The mode in which to open the stream.

Tags
throws
InvalidArgumentException

If the stream is not a valid resource.

Return values
mixed

__toString()

Gets the contents of the stream as a string.

public __toString() : string
Tags
throws
RuntimeException

If unable to read the stream contents.

Return values
string

The stream contents.

close()

Closes the stream and releases its resources.

public close() : void
Return values
void

detach()

Detaches the stream resource and returns it.

public detach() : resource|null
Return values
resource|null

The detached stream resource.

eof()

Checks if the end of the stream has been reached.

public eof() : bool
Return values
bool

True if the end of the stream has been reached, false otherwise.

getContents()

Gets the contents of the stream as a string.

public getContents() : string
Tags
throws
RuntimeException

If unable to read the stream contents.

Return values
string

The stream contents.

getMetadata()

Gets the metadata of the stream or a specific key of the metadata.

public getMetadata([string|null $key = null ]) : array<string|int, mixed>|mixed|null
Parameters
$key : string|null = null

The metadata key to retrieve.

Return values
array<string|int, mixed>|mixed|null

The metadata as an array, a specific metadata value, or null if the key is not found.

getSize()

Gets the size of the stream in bytes.

public getSize() : int|null
Return values
int|null

The size of the stream in bytes, or null if the size is unknown.

isReadable()

Checks if the stream is readable.

public isReadable() : bool
Return values
bool

True if the stream is readable, false otherwise.

isSeekable()

Checks if the stream is seekable.

public isSeekable() : bool
Return values
bool

True if the stream is seekable, false otherwise.

isWritable()

Checks if the stream is writable.

public isWritable() : bool
Return values
bool

True if the stream is writable, false otherwise.

read()

Reads data from the stream.

public read(int $length) : string
Parameters
$length : int

The number of bytes to read.

Tags
throws
RuntimeException

If unable to read the stream.

Return values
string

The data read from the stream.

rewind()

Seeks to a specific position in the stream.

public rewind() : mixed
Tags
throws
RuntimeException

on failure

Return values
mixed

seek()

เลื่อน pointer ไปยังตำแหน่งที่กำหนด

public seek(int $offset[, int $whence = SEEK_SET ]) : mixed
Parameters
$offset : int

ตำแหน่งของ pointer

$whence : int = SEEK_SET
Tags
throws
RuntimeException

on failure

Return values
mixed

tell()

คืนค่าตำแหน่งของ pointer ปัจจุบัน

public tell() : int
Tags
throws
RuntimeException

on error

Return values
int

write()

เขียนข้อมูลลงบน stream คืนค่าจำนวน byte ที่เขียน

public write(string $string) : int
Parameters
$string : string

ข้อมูลที่เขียน

Tags
throws
RuntimeException

on failure

Return values
int

Search results