writeBytes() public static method

Write to a stream; prevents partial writes.
public static writeBytes ( resource $stream, string $buf, integer $num_bytes = null ) : string
$stream resource
$buf string
$num_bytes integer
return string
 /**
  * Returns a stream representation of a string.
  *
  * @param string $contents The string
  *
  * @return resource The stream with the string contents.
  */
 private function getStreamFromString($contents)
 {
     $resource = fopen('php://memory', 'r+b');
     File::writeBytes($resource, $contents);
     rewind($resource);
     return $resource;
 }
 /**
  * Encrypts a string.
  *
  * @param string $contents The string to encrypt.
  *
  * @return string The encrypted string.
  */
 protected function encrypt($contents)
 {
     $resource = fopen('php://memory', 'r+b');
     File::writeBytes($resource, $contents);
     rewind($resource);
     $out = fopen('php://memory', 'r+b');
     File::encryptResource($resource, $out, $this->key);
     rewind($out);
     return stream_get_contents($out);
 }