public function StreamEncoder::decode in Replication 8.2
Same name and namespace in other branches
- 8 src/Encoder/StreamEncoder.php \Drupal\replication\Encoder\StreamEncoder::decode()
File
- src/
Encoder/ StreamEncoder.php, line 39
Class
Namespace
Drupal\replication\EncoderCode
public function decode($data, $format, array $context = []) {
if (!is_scalar($data)) {
throw new \InvalidArgumentException(sprintf('Data argument is not a scalar.'));
}
$uri = !empty($context['uri']) ? $context['uri'] : 'temporary://' . $this->random
->name();
$mode = !empty($context['mode']) ? $context['mode'] : 'w+b';
$stream = fopen($uri, $mode);
$data = $format == 'base64_stream' ? base64_decode($data) : $data;
fwrite($stream, $data);
// Put the file pointer back to the beginning.
rewind($stream);
return $stream;
}