@param EventStreamInterface $eventStream

@return CryptoEventStream
961172
public function createEncryptingStream(EventStreamInterface $eventStream)
    {
        return new CryptoEventStream(
            $eventStream,
            $this->cryptos,
            $this->encryptionKey,
            CryptoEventStream::ENCRYPT
        );
    }
641703
public function parse(NodeStream $stream)
    {
        $builder = new ClassBuilder();

        while (!$stream->is(TokenParser::NODE_EON)) {
            switch ($this->status) {
                case self::STAT_NONE:
                    $this->parseClass($builder, $stream);
                    break;
                case self::STAT_BODY:
                    $methodNodes = array(
                        TokenParser::NODE_PUBLIC_METHOD,
                        TokenParser::NODE_PROTECTED_METHOD,
                        TokenParser::NODE_PRIVATE_METHOD
                    );
                    if ($stream->is($methodNodes)) {
                        $this->parseMethod($builder, $stream);
                    } else {
                        $this->parseProperty($builder, $stream);
                    }
                    break;
                default:
                    $stream->next();
                    break;
            }
        }

        return $builder;
    }
194774
public function append(EventStreamInterface $eventStream)
    {
        /** @var $event Event */
        foreach ($eventStream as $event) {
            $version = $event->getVersion();
            $id = $event->getId();

            if (!isset($this->store[$id])) {
                $this->store[$id] = [];
            }

            if (isset($this->store[$id][$version])) {
                throw new DuplicateVersionException($version);
            }

            $this->store[$id][$version] = $event;
        }
    }
1131016
private function composeStreamSocket()
    {
        $ctx = stream_context_create();

        //Already checked if certificate exists.
        $certificate = $this->config['certificate'];
        stream_context_set_option($ctx, 'ssl', 'local_cert', $certificate);

        if (isset($this->config['passPhrase'])) {
            $passPhrase = $this->config['passPhrase'];
            if (!empty($passPhrase)) {
                stream_context_set_option($ctx, 'ssl', 'passphrase', $passPhrase);
            }
        }

        if (isset($this->config['passFile'])) {
            $passFile = $this->config['passFile'];
            if (file_exists($passFile)) {
                stream_context_set_option($ctx, 'ssl', 'local_pk', $passFile);
            }
        }

        return $ctx;
    }
699810
static function convertToResource(StreamInterface $stream)
    {
        # register wrapper if not
        $self = new self;
        if(!RegistryOfWrapperStream::isRegistered($self->getLabel()))
            RegistryOfWrapperStream::register($self);

        # make resource
        $mode = new AccessMode();
        (!$stream->isWritable()) ?: $mode->openForWrite();
        (!$stream->isReadable()) ?: $mode->openForRead();

        $label = $self->getLabel();

        $context  = new ContextStreamBase( $label, array('stream' => $stream) );
        $context  = $context->toContext();
        $resource = fopen($label.'://stream'
            , (string) $mode
            , null
            ## set options to wrapper
            , $context
        );

        return $resource;
    }
274019
private function writePayloadOnStreamForGivenToken($payload, $stream, $token)
    {
        $binaryMessage = sprintf('%s%s%s%s%s',
            chr(0),
            pack('n', 32),
            pack('H*', str_replace(' ', '', $token)),
            pack('n', strlen($payload)),
            $payload
        );

        fwrite($stream, $binaryMessage, strlen($binaryMessage));
    }
1158033
public static function fromStream(StreamInterface $stream): Xml
    {
        $xml = new DOMDocument();
        $xml->loadXML($stream->getContents());

        return new static($xml);
    }
338400
public function signStream($stream, $privateKey)
    {
        try {
            $virgilSourceStream = new VirgilStreamDataSource($stream);
            $virgilSourceStream->reset();

            return (new CryptoVirgilStreamSigner($this->hashAlgorithm))->sign(
                $virgilSourceStream,
                $privateKey
            );
        } catch (Exception $exception) {
            throw new ContentSigningException($exception->getMessage(), $exception->getCode());
        }
    }
1173375
protected function getStreamAsFile($stream)
    {
        // Get temporary file and name
        $file = tempnam(sys_get_temp_dir(), 'ssflysystem');
        $buffer = fopen($file, 'w');
        if (!$buffer) {
            throw new FlysystemException("Could not create temporary file");
        }

        // Transfer from given stream
        Util::rewindStream($stream);
        stream_copy_to_stream($stream, $buffer);
        if (!fclose($buffer)) {
            throw new FlysystemException("Could not write stream to temporary file");
        }

        return $file;
    }
1144131
public function addStream($stream)
    {
        while (!feof($stream)) {
            $freeBufferLength = $this->chunkSize - StringHelper::byteLength($this->_buffer);

            $streamChunk = fread($stream, $freeBufferLength);
            if ($streamChunk === false) {
                break;
            }
            $this->_buffer .= $streamChunk;
            $this->flushBuffer();
        }

        return $this;
    }
1363819
public static function forIn(): InputStream
    {
        if (null === self::$in) {
            self::$in      = new self();
            $inputEncoding = iconv_get_encoding('input_encoding');
            if ('UTF-8' !== $inputEncoding) {
                self::$in = new DecodingInputStream(self::$in, $inputEncoding);
            }
        }

        return self::$in;
    }
507138
private function decorateWithHashes(Stream $stream, array &$data)
    {
        // Decorate source with a hashing stream
        $hash = new PhpHash('sha256');
        return new HashingStream($stream, $hash, function ($result) use (&$data) {
            $data['ContentSHA256'] = bin2hex($result);
        });
    }
1214593
public function track(EventStream $stream)
    {
        if (!in_array($stream, $this->tracking, true)) {
            $this->tracking[] = $stream;
        }
    }
608616
public function serialize(DomainEventStream $domainEventStream)
    {
        $serializedDomainMessages = [];
        foreach ($domainEventStream as $domainMessage) {
            $serializedDomainMessages[] = $this->serializer->serialize($domainMessage);
        }

        return json_encode($serializedDomainMessages);
    }
214347
public function toTransactionResponseTransfer(StreamInterface $response): TransferInterface
    {
        $decryptedResponse = $this->decryptResponse($response);

        return $this->getResponseTransfer($decryptedResponse);
    }
1144588
private function decorateStream($encoding, StreamInterface $stream)
    {
        if ('chunked' == strtolower($encoding)) {
            return new DechunkStream($stream);
        }

        if ('compress' == strtolower($encoding)) {
            return new DecompressStream($stream);
        }

        if ('deflate' == strtolower($encoding)) {
            return new InflateStream($stream);
        }

        if ('gzip' == strtolower($encoding)) {
            return new GzipDecodeStream($stream);
        }

        return false;
    }
1116197
public static function decorate(StreamInterface $stream, array $methods)
    {
        // If any of the required methods were not provided, then simply
        // proxy to the decorated stream.
        foreach (array_diff(static::SLOTS, array_keys($methods)) as $diff) {
            $methods[$diff] = [$stream, $diff];
        }

        return new self($methods);
    }