@param resource $stream

@return Iterator
974465
public function parse($stream)
    {
        $tokeniser = new StreamTokeniser($this->csvFormat, $stream);
        $parser = new Parser();
        return $this->parseIterator(
            $parser->parse($tokeniser->getTokens())
        );
    }
623663
public function setStream(string $stream): self
    {
        $this->stream = $stream;
        $this->createByteCache();
        return $this;
    }
464323
public function attach($stream, $mode = 'r')
    {
        $this->stream = $stream;

        if (is_resource($stream)) {
            $this->resource = $stream;
        } elseif (is_string($stream)) {
            $this->resource = fopen($stream, $mode);
        } else {
            throw new \InvalidArgumentException('Invalid resource.');
        }

        return $this;
    }
236663
public function getIterator(): Iterator
    {
        $map = $this->map;
        foreach ($map as $ordinal => $value) {
            yield ($this->enumeration)::byOrdinal($ordinal) => $value;
        }
    }
166614
public static <T> Iterable<Indexed<T>> enumerate(Iterable<T> stream) {
        return new Iterable<Indexed<T>>() {

            @Override
            public Iterator<Indexed<T>> iterator() {
                Iterator<T> itr = stream.iterator();
                return new Iterator<Indexed<T>>() {

                    private int i = 0;

                    @Override
                    public boolean hasNext() {
                        return itr.hasNext();
                    }

                    @Override
                    public Indexed<T> next() {
                        Indexed<T> nextPair = new Indexed<T>(itr.next(), i);
                        i++;
                        return nextPair;
                    }
                };
            }
        };
    }
510391
public static <T> Stream<Map.Entry<Integer, T>> enumerate(Stream<T> stream) {
        Iterator<Map.Entry<Integer, T>> iterator = new Iterator<Map.Entry<Integer, T>>() {
            private int counter = 0;
            
            private final Iterator<T> internalIterator = stream.iterator();
            
            /** {@inheritDoc} */
            @Override
            public boolean hasNext() {
                return internalIterator.hasNext();
            }
            
            /** {@inheritDoc} */
            @Override
            public Map.Entry<Integer, T> next() {
                return new AbstractMap.SimpleImmutableEntry<>(counter++, internalIterator.next());
            }

            /** {@inheritDoc} */
            @Override
            public void remove() {
                throw new UnsupportedOperationException("This is a read-only iterator, remove operation is not supported.");
            }
        };
        return stream(iterator, stream.isParallel());
    }
891468
public function setInputStream($stream)
    {
        $stream = new Stream($stream ?: STDIN);
        $stream = FnStream::decorate($stream, [
            'read' => function ($length) use ($stream) {
                $ret = $stream->read($length);
                $this->onRead($ret);

                return $ret;
            },
        ]);
        $stream = StreamWrapper::getResource($stream);

        parent::setInputStream($stream);
    }
316660
public function parseExpr(Stream $stream)
    {
        if ($stream->current()->is(Token::TYPE_STRING | Token::TYPE_SINGLE_QUOTED)) {
            return new ValueFragmentNode($stream->expects(Token::TYPE_STRING | Token::TYPE_SINGLE_QUOTED)->getValue(), 'varchar');
        }

        if ($stream->current()->is(Token::TYPE_STRING | Token::TYPE_DOUBLE_QUOTED)) {
            return new FragmentNode($stream->expects(Token::TYPE_STRING | Token::TYPE_DOUBLE_QUOTED)->getValue());
        }

        if ($stream->current()->is(Token::TYPE_NUMBER)) {
            $value = $stream->expects(Token::TYPE_NUMBER)->getValue();

            return new ValueFragmentNode($value, strpos($value, '.') === false ? 'int8' : 'decimal');
        }

        if ($stream->current()->is(Token::TYPE_CONSTANT)) {
            $value = strtolower($stream->expects(Token::TYPE_CONSTANT)->getValue());

            return new ValueFragmentNode($value, in_array($value, ['true', 'false']) ? 'bool' : null);
        }

        if ($stream->current()->is(Token::TYPE_IDENTIFIER) && $stream->peek()->equals(Token::TYPE_SYMBOL, '(')) {
            $func = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();
            $args = [];

            $stream->expects(Token::TYPE_SYMBOL, '(');

            if (!$stream->current()->equals(Token::TYPE_SYMBOL, ')')) {
                do {
                    $args[] = $this->parseExpr($stream);
                } while ($stream->current()->equals(Token::TYPE_SYMBOL, ',') && $stream->expects(Token::TYPE_SYMBOL, ','));
            }

            $func = new FuncNode($func, $args);

            $stream->expects(Token::TYPE_SYMBOL, ')');

            return $func;
        }

        if ($stream->current()->is(Token::TYPE_IDENTIFIER)) {
            $path = [$stream->expects(Token::TYPE_IDENTIFIER)->getValue()];

            while ($stream->hasNext() && $stream->current()->equals(Token::TYPE_SYMBOL, '.')) {
                $stream->expects(Token::TYPE_SYMBOL, '.');

                $path[] = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();
            }

            return new ReferenceNode($path);
        }

        if ($stream->current()->equals(Token::TYPE_SYMBOL, '{')) {
            $stream->expects(Token::TYPE_SYMBOL, '{');

            $hash = [];

            if (!$stream->current()->equals(Token::TYPE_SYMBOL, '}')) {
                do {
                    $key = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();

                    $stream->expects(Token::TYPE_SYMBOL, ':');

                    $value = $this->parseExpr($stream);

                    $hash[$key] = $value;
                } while ($stream->current()->equals(Token::TYPE_SYMBOL, ',') && $stream->expects(Token::TYPE_SYMBOL, ','));
            }

            $stream->expects(Token::TYPE_SYMBOL, '}');

            return new RowFragmentNode($hash);
        }

        if ($stream->current()->equals(Token::TYPE_SYMBOL, '[')) {
            $stream->expects(Token::TYPE_SYMBOL, '[');

            $array = [];

            if (!$stream->current()->equals(Token::TYPE_SYMBOL, ']')) {
                do {
                    $array[] = $this->parseExpr($stream);
                } while ($stream->current()->equals(Token::TYPE_SYMBOL, ',') && $stream->expects(Token::TYPE_SYMBOL, ','));
            }

            $stream->expects(Token::TYPE_SYMBOL, ']');

            return new SetFragmentNode($array);
        }

        throw new \Exception(sprintf(
            'Fails to parse stream "%s". Unexpected token %s at line %d.',
            $stream->humanize(),
            Token::humanize($stream->current()->getType()),
            $stream->current()->getLine()
        ));
    }
632332
public static function fromStream(StreamInterface $stream)
    {
        if (! $stream->isReadable() || ! $stream->isSeekable()) {
            throw new InvalidArgumentException('Message stream must be both readable and seekable');
        }

        $stream->rewind();

        list($method, $requestTarget, $version) = self::getRequestLine($stream);
        $uri = self::createUriFromRequestTarget($requestTarget);

        list($headers, $body) = self::splitStream($stream);

        return (new Request($uri, $method, $body, $headers))
            ->withProtocolVersion($version)
            ->withRequestTarget($requestTarget);
    }
886588
private function parseImportList(Stream $stream)
    {
        $list = [];

        do {
            $resource = $this->parseIdentifier($stream);

            if ($stream->current()->equals(Token::TYPE_KEYWORD, 'as')) {
                $stream->expects(Token::TYPE_KEYWORD, 'as');

                $alias = $this->parseIdentifier($stream);
            } else {
                $alias = $resource;
            }

            $list[$resource] = $alias;
        } while ($stream->current()->equals(Token::TYPE_SYMBOL, ',') && $stream->expects(Token::TYPE_SYMBOL, ','));

        return $list;
    }
417977
public function getCollection(string $resourceClass, string $operationName = null): iterable
    {
        $collection = $this->repository->findAll($resourceClass);

        return new Paginator(new GenericPaginatedDomainCollection((static function () use ($collection): iterable {
            foreach ($collection as $document) {
                yield $document->toProjection();
            }
        })(), $collection->getOffset(), $collection->getLimit(), (float) \count($collection), $collection->getTotalCount()));
    }
228742
protected function initStream($stream)
    {
        expect_type(
            $stream,
            ['stream resource', 'string'],
            \TypeError::class,
            "Expected stream resource or uri (string), %s given"
        );

        if (is_string($stream)) {
            $stream = $this->openStream($stream);
        }

        $meta = stream_get_meta_data($stream);

        if ($meta['mode'] === 'r') {
            throw new \InvalidArgumentException("Stream \"{$meta['uri']}\" is not writable");
        }

        return $stream;
    }
1131909
public function pipe($stream)
    {
        $offset = $stream->tell();
        $result = stream_copy_to_stream($this->resource(), $stream->resource());
        if ($stream->isSeekable()) {
            $stream->seek($offset);
        }
        return $result;
    }
889067
public function toStream($stream)
    {
        $bytesWritten = 0;
        foreach ($this->getChunkCursor() as $chunk) {
            $bytesWritten += fwrite($stream, $chunk['data']->getData());
        }
        return $bytesWritten;
    }
160546
public function hasStream($stream)
    {
        $isInputStream = $stream == $this->getInputStream();
        $isOutputStream = $stream == $this->getOutputStream();
        $isErrStream = $stream == $this->getErrorStream();

        return $isInputStream || $isOutputStream || $isErrStream;
    }
227982
public function setStream($stream)
    {
        // streams have to be cached to file first
        $meta = @stream_get_meta_data($stream);
        if (!$meta || !$meta['mode'] || !in_array($meta['mode'], self::$readableModes, true) || $meta['eof']) {
            throw new Exception(
                'setStream() expects parameter stream to be readable stream resource.'
            );
        }

        /** @var resource $tmp_fp */
        $tmp_fp = tmpfile();
        if ($tmp_fp) {
            while (!feof($stream)) {
                fwrite($tmp_fp, fread($stream, 2028));
            }

            if (fread($tmp_fp, 1) != "\n") {
                fwrite($tmp_fp, PHP_EOL);
            }

            fseek($tmp_fp, 0);
            $this->stream = &$tmp_fp;
        } else {
            throw new Exception(
                'Could not create temporary files for attachments. Your tmp directory may be unwritable by PHP.'
            );
        }
        fclose($stream);

        $this->resource = mailparse_msg_create();
        // parses the message incrementally (low memory usage but slower)
        while (!feof($this->stream)) {
            mailparse_msg_parse($this->resource, fread($this->stream, 2082));
        }
        $this->parse();

        return $this;
    }
1213094
protected function limitPartStream(Stream $stream)
    {
        // Limit what is read from the stream to the part size.
        return new Psr7\LimitStream(
            $stream,
            $this->state->getPartSize(),
            $this->source->tell()
        );
    }