public copyBodyStream ( resource $sourceStream, integer $maxlength = null, integer $offset ) : integer | ||
$sourceStream | resource | The file pointer to source stream |
$maxlength | integer | The max length to read from source stream |
$offset | integer | The offset from source stream to read |
return | integer | The total number of bytes copied |
public function copyBodyStream($sourceStream, $maxlength = null, $offset = 0)
{
// check if a stream has been passed
if (is_resource($sourceStream)) {
if ($offset && $maxlength) {
$this->bodyStream = stream_get_contents($sourceStream, $maxlength, $offset);
}
if (!$offset && $maxlength) {
$this->bodyStream = stream_get_contents($sourceStream, $maxlength);
}
if (!$offset && !$maxlength) {
$this->bodyStream = stream_get_contents($sourceStream);
}
} else {
// if not, copy the string
$this->bodyStream = substr($sourceStream, $offset, $maxlength);
}
// return the string length
return strlen($this->bodyStream);
}