StreamSegment
in package
implements
StreamInterface
The stream segment class allows an application to restrict access to a stream to a specific segment of it.
This class comes in handy when doing HTTP range requests where the sender determines a segment of a file that it wishes to receive.
Tags
Interfaces, Classes and Traits
- StreamInterface
Table of Contents
- $end : int|null
- The last index to be read when the application is trying to read the source stream.
- $src : StreamInterface
- $start : int
- Determines the first index of the stream that should be returned when reading from this segment.
- __construct() : mixed
- __toString() : string
- The toString method is a convenience that outputs the stream as a string. In the case of segments, we will only output the appropriate window.
- close() : void
- If we close the segment, we just forward this to the underlying stream, closing it and freeing it's resources.
- detach() : resource|null
- Detaches the stream from the underlying resource, making it unable to operate on the stream that it wraps.
- eof() : bool
- Returns whether the stream has been read to it's end. Please note that the underlying stream may not have reached it's end, but the segment may be exhausted.
- getContents() : string
- Returns the entire content of the stream segment.
- getEnd() : int
- getMetadata() : mixed
- The metadata of the segment is purely the metadata of the underlying stream. Please note that information about the size, etc may be incorrect.
- getSize() : int
- getStart() : int
- isReadable() : bool
- Returns true if the stream is readable. Segments are always readable, since their purpose is to provide a reading fence.
- isSeekable() : bool
- Segments must be seekable, since they depend on the underlying stream being seekable.
- isWritable() : bool
- Returns whether the underlying stream is writable. There's not much use to using stream segments for writing, but they will 'fence' the application, allowing it to only write within the segment.
- read() : string
- rewind() : StreamSegment
- seek() : StreamSegment
- tell() : int
- write() : int
- Write to the underlying stream. This method will respect the end boundary, which means that if your application is trying to write 6KB to a 4KB window, only the first 4KB will be written and the rest discarded.
Properties
$end
The last index to be read when the application is trying to read the source stream.
private
int|null
$end
$src
private
StreamInterface
$src
$start
Determines the first index of the stream that should be returned when reading from this segment.
private
int
$start
Methods
__construct()
public
__construct(StreamInterface $src, int $start[, int|null $end = null ]) : mixed
Parameters
- $src : StreamInterface
- $start : int
- $end : int|null = null
-
The last INDEX of the stream to be included
Tags
Return values
mixed —__toString()
The toString method is a convenience that outputs the stream as a string. In the case of segments, we will only output the appropriate window.
public
__toString() : string
Return values
string —close()
If we close the segment, we just forward this to the underlying stream, closing it and freeing it's resources.
public
close() : void
Return values
void —detach()
Detaches the stream from the underlying resource, making it unable to operate on the stream that it wraps.
public
detach() : resource|null
Return values
resource|null —eof()
Returns whether the stream has been read to it's end. Please note that the underlying stream may not have reached it's end, but the segment may be exhausted.
public
eof() : bool
Return values
bool —getContents()
Returns the entire content of the stream segment.
public
getContents() : string
Return values
string —getEnd()
public
getEnd() : int
Return values
int —getMetadata()
The metadata of the segment is purely the metadata of the underlying stream. Please note that information about the size, etc may be incorrect.
public
getMetadata([mixed $key = null ]) : mixed
Parameters
- $key : mixed = null
Return values
mixed —getSize()
public
getSize() : int
Return values
int —getStart()
public
getStart() : int
Return values
int —isReadable()
Returns true if the stream is readable. Segments are always readable, since their purpose is to provide a reading fence.
public
isReadable() : bool
Return values
bool —isSeekable()
Segments must be seekable, since they depend on the underlying stream being seekable.
public
isSeekable() : bool
Return values
bool —isWritable()
Returns whether the underlying stream is writable. There's not much use to using stream segments for writing, but they will 'fence' the application, allowing it to only write within the segment.
public
isWritable() : bool
Return values
bool —read()
public
read([int $length = null ]) : string
Parameters
- $length : int = null
Return values
string —rewind()
public
rewind() : StreamSegment
Return values
StreamSegment —seek()
public
seek(int $position[, int $whence = SEEK_SET ]) : StreamSegment
Parameters
- $position : int
- $whence : int = SEEK_SET
Return values
StreamSegment —tell()
public
tell() : int
Return values
int —write()
Write to the underlying stream. This method will respect the end boundary, which means that if your application is trying to write 6KB to a 4KB window, only the first 4KB will be written and the rest discarded.
public
write(string $string) : int
Parameters
- $string : string