<commit_before><?php

/*
 * This file is part of the 'org.octris.core' package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace org\octris\core\fs {
    /**
     * Implements an iterator for a file.
     *
     * @octdoc      c:type/fileiterator
     * @copyright   copyright (c) 2012 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class fileiterator implements \Iterator, \SeekableIterator
    /**/
    {
        /**
         * File handle.
         *
         * @octdoc  p:fileiterator/$fh
         * @var     resource
         */
        protected $fh = null;
        /**/
        
        /**
         * File handling flags.
         * 
         * @octdoc  p:fileiterator/$flags
         * @var     int
         */
        protected $flags = 0;
        /**/

        /**
         * Current row number.
         *
         * @octdoc  p:fileiterator/$row
         * @var     int
         */
        protected $row = null;
        /**/

        /**
         * Contents of current line of file.
         *
         * @octdoc  p:fileiterator/$current
         * @var     string
         */
        protected $current = '';
        /**/
        
        /**
         * Whether file is seekable.
         *
         * @octdoc  p:fileiterator/$is_seekable
         * @var     bool
         */
        protected $is_seekable;
        /**/

        /**
         * Constructor.
         *
         * @octdoc  p:fileiterator/__construct
         * @param   string                      $uri                        URI to open.
         * @param   int                         $flags                      Optional flags.
         */
        public function __construct($uri, $flags = 0)
        /**/
        {
            if (!($this->fh = @fopen($uri, 'r'))) {
                $info = error_get_last();

                throw new \Exception($info['message'], $info['type']);
            } else {
                $meta = stream_get_meta_data($this->fh);

                $this->is_seekable = $meta['seekable'];
                $this->flags       = $flags;
            }<commit_msg>it's now allowed to specify a resource for iterator, too<commit_after><?php

/*
 * This file is part of the 'org.octris.core' package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace org\octris\core\fs {
    /**
     * Implements an iterator for a file.
     *
     * @octdoc      c:type/fileiterator
     * @copyright   copyright (c) 2012 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class fileiterator implements \Iterator, \SeekableIterator
    /**/
    {
        /**
         * File handle.
         *
         * @octdoc  p:fileiterator/$fh
         * @var     resource
         */
        protected $fh = null;
        /**/
        
        /**
         * File handling flags.
         * 
         * @octdoc  p:fileiterator/$flags
         * @var     int
         */
        protected $flags = 0;
        /**/

        /**
         * Current row number.
         *
         * @octdoc  p:fileiterator/$row
         * @var     int
         */
        protected $row = null;
        /**/

        /**
         * Contents of current line of file.
         *
         * @octdoc  p:fileiterator/$current
         * @var     string
         */
        protected $current = '';
        /**/
        
        /**
         * Whether file is seekable.
         *
         * @octdoc  p:fileiterator/$is_seekable
         * @var     bool
         */
        protected $is_seekable;
        /**/

        /**
         * Constructor.
         *
         * @octdoc  p:fileiterator/__construct
         * @param   string|resource             $file                       Stream resource or filename.
         * @param   int                         $flags                      Optional flags.
         */
        public function __construct($file, $flags = 0)
        /**/
        {
            if (is_resource($file)) {
                $meta = stream_get_meta_data($file);

                $this->fh = $file;

                $this->is_seekable = $meta['seekable'];
                $this->flags       = $flags;
            } elseif (!($this->fh = @fopen($uri, 'r'))) {
                $info = error_get_last();

                throw new \Exception($info['message'], $info['type']);
            } else {
                $meta = stream_get_meta_data($this->fh);

                $this->is_seekable = $meta['seekable'];
                $this->flags       = $flags;
            }
{'fraction_non_alphanumeric': 0.12449543233482048, 'fraction_numerical': 0.0025493945188017845, 'mean_word_length': 1.1537053979871912, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4529123', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1272, 'n_words': 304}