Writes out headers for $this->part and follows them with an empty line.

@param StreamInterface $stream
771
public function writePartHeadersTo(StreamInterface $stream)
    {
        foreach ($this->getPartHeadersIterator() as $header) {
            $stream->write("${header[0]}: ${header[1]}\r\n");
        }
        $stream->write("\r\n");
    }
538926
public function importGedcomFile(StreamInterface $stream, string $filename): void
    {
        // Read the file in blocks of roughly 64K. Ensure that each block
        // contains complete gedcom records. This will ensure we don’t split
        // multi-byte characters, as well as simplifying the code to import
        // each block.

        $file_data = '';

        $this->deleteGenealogyData((bool) $this->getPreference('keep_media'));
        $this->setPreference('gedcom_filename', $filename);
        $this->setPreference('imported', '0');

        while (!$stream->eof()) {
            $file_data .= $stream->read(65536);
            // There is no strrpos() function that searches for substrings :-(
            for ($pos = strlen($file_data) - 1; $pos > 0; --$pos) {
                if ($file_data[$pos] === '0' && ($file_data[$pos - 1] === "\n" || $file_data[$pos - 1] === "\r")) {
                    // We’ve found the last record boundary in this chunk of data
                    break;
                }
            }
            if ($pos) {
                DB::table('gedcom_chunk')->insert([
                    'gedcom_id'  => $this->id,
                    'chunk_data' => substr($file_data, 0, $pos),
                ]);

                $file_data = substr($file_data, $pos);
            }
        }
        DB::table('gedcom_chunk')->insert([
            'gedcom_id'  => $this->id,
            'chunk_data' => $file_data,
        ]);

        $stream->close();
    }
220972
public function attachContentStream(StreamInterface $stream, $streamCharset = MailMimeParser::DEFAULT_CHARSET)
    {
        if ($this->contentStream !== null && $this->contentStream !== $stream) {
            $this->contentStream->close();
        }
        $this->contentStream = $stream;
        $ch = ($this->charsetOverride !== null) ? $this->charsetOverride : $this->getCharset();
        if ($ch !== null && $streamCharset !== $ch) {
            $this->charsetOverride = $streamCharset;
        }
        $this->ignoreTransferEncoding = true;
        $this->partStreamFilterManager->setStream($stream);
        $this->onChange();
    }
524846
public function getNodeFrom(StreamInterface $stream)
    {
        // Iterate and append to $this->chunk
        while ($this->prepareChunk($stream)) {
            $this->firstRun = false;
            // Shave off elements
            while ($shaved = $this->shave()) {
                list($element, $data) = $shaved;

                // Analyze element
                list($opening, $closing, $depth) = $this->getEdges($element);

                // Update depth
                $this->depth += $depth;

                $flush = false;
                $captureOnce = false;

                // Capture or don't?
                if ($this->depth === $this->options["captureDepth"] && $depth > 0) {
                    // Yes, we've just entered capture depth, start capturing
                    $this->capture = true;
                } else if ($this->depth === $this->options["captureDepth"] - 1 && $depth < 0) {
                    // No, we've just exited capture depth, stop capturing and prepare for flush      
                    $flush = true;
                    $this->capture = false;
                    
                    // ..but include this last node
                    $this->shaved .= $data;
                } else if ($this->options["extractContainer"] && $this->depth < $this->options["captureDepth"]) {
                    // We're outside of our capture scope, save to the special buffer if extractContainer is true
                    $this->containerXml .= $element;
                } else if ($depth === 0 && $this->depth + 1 === $this->options["captureDepth"]) {
                    // Self-closing element - capture this element and flush but don't start capturing everything yet
                    $captureOnce = true;
                    $flush = true;
                }

                // Capture the last retrieved node
                if ($this->capture || $captureOnce) {
                    $this->shaved .= $data;
                }

                if ($flush) {
                    // Flush the whole node and start over on the next
                    $flush = $this->shaved;
                    $this->shaved = null;

                    return $flush;
                }
            }
        }

        return false;
	}
547187
public function writeUTF($stream)
    {
        $this->writeInt($this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream));
        $this->_stream.= $stream;
        return $this;
    }
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;
    }
327793
public function initializeState(DomainEventStream $stream): void
    {
        foreach ($stream as $message) {
            ++$this->playhead;
            $this->handleRecursively($message->getPayload());
        }
    }
217762
public void write(@NonNull Normalizer normalizer, @NonNull OutputStream stream) throws IOException {
        NormalizerSerializerStrategy strategy = getStrategy(normalizer);

        writeHeader(stream, Header.fromStrategy(strategy));
        //noinspection unchecked
        strategy.write(normalizer, stream);
    }
20637
public void write(PrintStream stream) {
        this.output = stream;
        dispatch(base, false);
        stream.flush();
    }
265539
public function newInstance(PartBuilder $partBuilder, StreamInterface $stream = null)
    {
        $contentStream = null;
        if ($stream !== null) {
            $contentStream = $this->streamFactory->getLimitedContentStream($stream, $partBuilder);
        }
        return new Message(
            $this->partStreamFilterManagerFactory->newInstance(),
            $this->streamFactory,
            $this->partFilterFactory,
            $partBuilder,
            $this->messageHelperService,
            $stream,
            $contentStream
        );
    }
865834
private function dumpStream(Stream $body)
    {
        $body = $body->getSize() < $this->maxStreamSize
            ? trim($body->getContents())
            : 'stream(size=' . $body->getSize() . ')';

        return $body ?: '<empty>';
    }
680951
protected function printMessage(
        OutputInterface $output,
        $header,
        $body
    ) {
        $message = sprintf(
            '<header>%s</header> <body>%s</body>',
            '[' . $header . ']',
            $body
        );
        $output->writeln($message);
    }
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);
        });
    }
328712
public function sendResponse(ResponseInterface $response): void
    {
        // Send all the headers
        \http_response_code($response->getStatusCode());
        foreach ($response->getHeaders() as $headerName => $headerValues) {
            /** @var string[] $headerValues */
            foreach ($headerValues as $headerValue) {
                \header("$headerName: $headerValue", false);
            }
        }

        // Get the body, rewind it if possible
        $body = $response->getBody();
        if ($body->isSeekable()) {
            $body->rewind();
        }

        // If the body is not readable do not send any body to the client
        if (!$body->isReadable()) {
            return;
        }

        // Send the body (by chunk if specified in the container using streamReadLength value)
        if (null === $this->streamReadLength) {
            echo $body->__toString();

            return;
        }

        while (!$body->eof()) {
            echo $body->read($this->streamReadLength);
        }
    }
1369294
public static function localFilename(StreamInterface $stream)
    {
        self::register();

        $uri = 'spiral://' . spl_object_hash($stream);
        self::$uris[$uri] = $stream;

        return $uri;
    }
607807
public function useStream(Stream $stream): ControllerInterface
    {
        $this->soap("AVTransport", "SetAVTransportURI", [
            "CurrentURI"            =>  $stream->getUri(),
            "CurrentURIMetaData"    =>  $stream->getMetaData(),
        ]);

        return $this;
    }
868472
public function addWriteStream($stream, callable $listener)
    {
        $this->emit('addWriteStream', [$stream, $listener]);
        $this->loop->addWriteStream($stream, function ($stream) use ($listener) {
            $this->emit('writeStreamTick', [$stream, $listener]);
            $listener($stream, $this);
        });
    }