You are here

public function StreamEncoder::encode in Replication 8.2

Same name and namespace in other branches
  1. 8 src/Encoder/StreamEncoder.php \Drupal\replication\Encoder\StreamEncoder::encode()

File

src/Encoder/StreamEncoder.php, line 28

Class

StreamEncoder

Namespace

Drupal\replication\Encoder

Code

public function encode($data, $format, array $context = []) {
  if (!is_resource($data)) {
    throw new \InvalidArgumentException(sprintf('Data argument is not a resource.'));
  }
  $contents = stream_get_contents($data);
  return $format == 'base64_stream' ? base64_encode($contents) : $contents;
}