Constants

STREAM_TYPE

STREAM_TYPE = 'stream_type'

WRAPPER_TYPE

WRAPPER_TYPE = 'wrapper_type'

IS_LOCAL

IS_LOCAL = 'is_local'

IS_READABLE

IS_READABLE = 'is_readable'

IS_WRITABLE

IS_WRITABLE = 'is_writable'

SEEKABLE

SEEKABLE = 'seekable'

Properties

$stream

$stream : resource

Type

resource — Stream resource

$size

$size : integer

Type

integer — Size of the stream contents in bytes

$cache

$cache : array

Type

array — Stream cached data

$customData

$customData : array

Type

array — Custom stream data

$readWriteHash

$readWriteHash : array

Type

array — Hash table of readable and writeable stream types for fast lookups

$contentEncoding

$contentEncoding : boolean

Type

boolean — Content-Encoding of the entity body if known

$rewindFunction

$rewindFunction : callable

Type

callable — Method to invoke for rewinding a stream

Methods

__construct()

__construct(resource  $stream, integer  $size = null) 

Parameters

resource $stream

Stream resource to wrap

integer $size

Size of the stream in bytes. Only pass if the size cannot be obtained from the stream.

Throws

\Guzzle\Common\Exception\InvalidArgumentException

if the stream is not a stream resource

__destruct()

__destruct() 

Closes the stream when the helper is destructed

__toString()

__toString() : string

Convert the stream to a string if the stream is readable and the stream is seekable.

Returns

string

close()

close() 

Close the underlying stream

getHash()

getHash(\Guzzle\Stream\StreamInterface  $stream, string  $algo, boolean  $rawOutput = false) : boolean|string

Calculate a hash of a Stream

Parameters

\Guzzle\Stream\StreamInterface $stream

Stream to calculate the hash for

string $algo

Hash algorithm (e.g. md5, crc32, etc)

boolean $rawOutput

Whether or not to use raw output

Returns

boolean|string —

Returns false on failure or a hash string on success

getMetaData()

getMetaData(string  $key = null) : array|mixed|null

Get stream metadata

Parameters

string $key

Specific metadata to retrieve

Returns

array|mixed|null

getStream()

getStream() : resource

Get the stream resource

Returns

resource

setStream()

setStream(resource  $stream, integer  $size = null) : self

Set the stream that is wrapped by the object

Parameters

resource $stream

Stream resource to wrap

integer $size

Size of the stream in bytes. Only pass if the size cannot be obtained from the stream.

Returns

self

detachStream()

detachStream() : self

Detach the current stream resource

Returns

self

getWrapper()

getWrapper() : string

Get the stream wrapper type

Returns

string

getWrapperData()

getWrapperData() : array

Wrapper specific data attached to this stream.

Returns

array

getStreamType()

getStreamType() : string

Get a label describing the underlying implementation of the stream

Returns

string

getUri()

getUri() : string

Get the URI/filename associated with this stream

Returns

string

getSize()

getSize() : integer|boolean

Get the size of the stream if able

Returns

integer|boolean

isReadable()

isReadable() : boolean

Check if the stream is readable

Returns

boolean

isRepeatable()

isRepeatable() : boolean

Check if the stream is repeatable

Returns

boolean

isWritable()

isWritable() : boolean

Check if the stream is writable

Returns

boolean

isConsumed()

isConsumed() : boolean

Check if the stream has been consumed

Returns

boolean

feof()

feof() : boolean

Alias of isConsumed

Returns

boolean

isLocal()

isLocal() : boolean

Check if the stream is a local stream vs a remote stream

Returns

boolean

isSeekable()

isSeekable() : boolean

Check if the string is repeatable

Returns

boolean

setSize()

setSize(integer  $size) : self

Specify the size of the stream in bytes

Parameters

integer $size

Size of the stream contents in bytes

Returns

self

seek()

seek(integer  $offset, integer  $whence = SEEK_SET) : boolean

Seek to a position in the stream

Parameters

integer $offset

Stream offset

integer $whence

Where the offset is applied

Returns

boolean —

Returns TRUE on success or FALSE on failure

read()

read(integer  $length) : string|boolean

Read data from the stream

Parameters

integer $length

Up to length number of bytes read.

Returns

string|boolean —

Returns the data read from the stream or FALSE on failure or EOF

write()

write(string  $string) : integer|boolean

Write data to the stream

Parameters

string $string

The string that is to be written.

Returns

integer|boolean —

Returns the number of bytes written to the stream on success or FALSE on failure.

ftell()

ftell() : integer|boolean

Returns the current position of the file read/write pointer

Returns

integer|boolean —

Returns the position of the file pointer or false on error

rewind()

rewind() : boolean

Rewind to the beginning of the stream

Returns

boolean —

Returns true on success or false on failure

readLine()

readLine(integer  $maxLength = null) : string|boolean

Read a line from the stream up to the maximum allowed buffer length

Parameters

integer $maxLength

Maximum buffer length

Returns

string|boolean

setCustomData()

setCustomData(string  $key, mixed  $value) : self

Set custom data on the stream

Parameters

string $key

Key to set

mixed $value

Value to set

Returns

self

getCustomData()

getCustomData(string  $key) : null|mixed

Get custom data from the stream

Parameters

string $key

Key to retrieve

Returns

null|mixed

factory()

factory(resource|string|\Guzzle\Http\EntityBody  $resource = '', integer  $size = null) : \Guzzle\Http\EntityBody

Create a new EntityBody based on the input type

Parameters

resource|string|\Guzzle\Http\EntityBody $resource

Entity body data

integer $size

Size of the data contained in the resource

Throws

\Guzzle\Common\Exception\InvalidArgumentException

if the $resource arg is not a resource or string

Returns

\Guzzle\Http\EntityBody

setRewindFunction()

setRewindFunction(mixed  $callable) : self

Specify a custom callback used to rewind a non-seekable stream. This can be useful entity enclosing requests that are redirected.

Parameters

mixed $callable

Callable to invoke to rewind a non-seekable stream. The callback must accept an EntityBodyInterface object, perform the rewind if possible, and return a boolean representing whether or not the rewind was successful.

Returns

self

fromString()

fromString(string  $string) : \Guzzle\Http\EntityBody

Create a new EntityBody from a string

Parameters

string $string

String of data

Returns

\Guzzle\Http\EntityBody

compress()

compress(string  $filter = 'zlib.deflate') : boolean

If the stream is readable, compress the data in the stream using deflate compression. The uncompressed stream is then closed, and the compressed stream then becomes the wrapped stream.

Parameters

string $filter

Compression filter

Returns

boolean —

Returns TRUE on success or FALSE on failure

uncompress()

uncompress(string  $filter = 'zlib.inflate') : boolean

Decompress a deflated string. Once uncompressed, the uncompressed string is then used as the wrapped stream.

Parameters

string $filter

De-compression filter

Returns

boolean —

Returns TRUE on success or FALSE on failure

getContentLength()

getContentLength() : integer|boolean

Get the Content-Length of the entity body if possible (alias of getSize)

Returns

integer|boolean —

Returns the Content-Length or false on failure

getContentType()

getContentType() : string|null

Guess the Content-Type of a local stream

Returns

string|null

getContentMd5()

getContentMd5(boolean  $rawOutput = false, boolean  $base64Encode = false) : boolean|string

Get an MD5 checksum of the stream's contents

Parameters

boolean $rawOutput

Whether or not to use raw output

boolean $base64Encode

Whether or not to base64 encode raw output (only if raw output is true)

Returns

boolean|string —

Returns an MD5 string on success or FALSE on failure

calculateMd5()

calculateMd5(\Guzzle\Http\EntityBodyInterface  $body, boolean  $rawOutput = false, boolean  $base64Encode = false) : boolean|string

Calculate the MD5 hash of an entity body

Parameters

\Guzzle\Http\EntityBodyInterface $body

Entity body to calculate the hash for

boolean $rawOutput

Whether or not to use raw output

boolean $base64Encode

Whether or not to base64 encode raw output (only if raw output is true)

Returns

boolean|string —

Returns an MD5 string on success or FALSE on failure

setStreamFilterContentEncoding()

setStreamFilterContentEncoding(  $streamFilterContentEncoding) 

Parameters

$streamFilterContentEncoding

getContentEncoding()

getContentEncoding() : boolean|string

Get the Content-Encoding of the EntityBody

Returns

boolean|string

rebuildCache()

rebuildCache() 

Reprocess stream metadata

handleCompression()

handleCompression(  $filter,   $offsetStart) 

Parameters

$filter
$offsetStart