/** * @param CM_File $file * @param CM_File_Filesystem_Adapter $adapterSource * @param CM_File_Filesystem_Adapter $adapterDestination * @throws CM_Exception */ protected function _copyToFileStreaming(CM_File $file, CM_File_Filesystem_Adapter $adapterSource, CM_File_Filesystem_Adapter $adapterDestination) { /** @var CM_File_Filesystem_Adapter_StreamInterface $adapterSource */ /** @var CM_File_Filesystem_Adapter_StreamInterface $adapterDestination */ $streamSource = $adapterSource->getStreamRead($this->getPath()); $adapterDestination->writeStream($file->getPath(), $streamSource); $sizeDestination = $file->getSize(); $sizeSource = $this->getSize(); if ($sizeSource !== $sizeDestination) { throw new CM_Exception('Copy failed', null, ['Source' => $this->getPath(), 'Destination' => $file->getPath(), 'Original size' => $sizeSource, 'Bytes copied' => $sizeDestination, 'Source adapter' => get_class($adapterSource), 'Destination adapter' => get_class($adapterDestination)]); } if (is_resource($streamSource) && !@fclose($streamSource)) { throw new CM_Exception('Could not close stream for path', null, ['path' => $this->getPath(), 'Source adapter' => get_class($adapterSource)]); } }