/** * Perform the copy between this stream and the destination. * @param StreamInterface $destination * @param int|null $bufferSize */ protected function internalCopyTo(StreamInterface $destination, $bufferSize = null) { if (null !== $bufferSize && $bufferSize <= 0) { throw new Exception\InvalidArgumentException('bufferSize', $bufferSize, 'Parameter "bufferSize" must be greater than 0.'); } // Use native implementation if possible. if ($destination instanceof self) { // Ensure pending data is dealt with, as we are bypassing write() $destination->flush(); stream_copy_to_stream($this->handle, $destination->handle); return; } // Copy in chunks $bufferSize = $bufferSize ?: $this->defaultCopyBufferSize; while (($data = $this->read($bufferSize)) !== null) { $destination->write($data); } }
public function write($data, $length = null) { $this->stream->write($data, $length); }
public function copyTo(StreamInterface $destination, $bufferSize = null) { if (null === $destination) { throw new Exception\InvalidArgumentException('destination'); } if (!$this->canRead() && !$this->canWrite()) { throw new Exception\ObjectDisposedException('this'); } if (!$destination->canRead() && !$destination->canWrite()) { throw new Exception\ObjectDisposedException('destination'); } if (!$this->canRead()) { throw new Exception\NotSupportedException(); } if (!$destination->canWrite()) { throw new Exception\NotSupportedException(); } if (null !== $bufferSize && $bufferSize <= 0) { throw new Exception\InvalidArgumentException('bufferSize', $bufferSize, 'Parameter "bufferSize" must be greater than 0.'); } // Copy in chunks $bufferSize = $bufferSize ?: $this->defaultCopyBufferSize; while (($data = $this->read($bufferSize)) !== null) { $destination->write($data); } }
public function write($data, $length = null) { $this->initializeStream(); $this->stream->write($data, $length); }