public function length()
    {
        if ($this->_limit !== null) {
            return $this->_limit;
        }
        if ($this->_length !== null) {
            return $this->_length;
        }
        if ($this->isSeekable()) {
            $old = $this->tell();

            $begin = $this->rewind();
            $end = $this->end();

            $this->seek($old);
            return $end - $begin;
        }
    }