Parses length-encoded binary integer
@return integer Result
343244
public function parseEncodedBinary()
    {
        $f = ord($this->read(1));
        if ($f <= 250) {
            return $f;
        }
        if ($f === 251) {
            return null;
        }
        if ($f === 255) {
            return false;
        }
        if ($f === 252) {
            return Binary::bytes2int($this->read(2), true);
        }
        if ($f === 253) {
            return Binary::bytes2int($this->read(3), true);
        }
        return Binary::bytes2int($this->read(8), true);
    }
436025
public function readInt64()
    {

        // We have the pack 64-bit codes available. See: http://php.net/manual/en/function.pack.php
        if (version_compare(PHP_VERSION, '5.6.3') >= 0 && PHP_INT_SIZE == 8) {
            // Change the integer type we are looking up
            switch ($this->number_type) {
                case self::NUMBER_TYPE_BIGENDIAN:
                    $type = 'Jint';
                    break;

                case self::NUMBER_TYPE_LITTLEENDIAN:
                    $type = 'Pint';
                    break;

                default:
                    $type = 'Qint';
            }

            $int64 = unpack($type, $this->read(8));

            $int = $int64['int'];

            unset($int64);
        } else {
            if ($this->number_type == self::NUMBER_TYPE_BIGENDIAN) {
                $high = $this->readInt32();
                $low = $this->readInt32();
            } else {
                $low = $this->readInt32();
                $high = $this->readInt32();
            }

            // We have to determine the number via bitwise
            $int = ($high << 32) | $low;

            unset($low, $high);
        }

        return $int;
    }
1120259
public int readLength() throws IOException {
		int length = 0;

		byte b = (byte) this.read();

		// This is short form. The short form can be used if the number of
		// octets in the Value part is less than or
		// equal to 127, and can be used whether the Value part is primitive or
		// constructed. This form is identified by
		// encoding bit 8 as zero, with the length count in bits 7 to 1 (as
		// usual, with bit 7 the most significant bit
		// of the length).
		if ((b & 0x80) == 0) {
			return b;
		}

		// This is indefinite form. The indefinite form of length can only be
		// used (but does not have to be) if the V
		// part is constructed, that
		// is to say, consists of a series of TLVs. In the indefinite form of
		// length the first bit of the first octet is
		// set to 1, as for the long form, but the value N is set to zero.
		b = (byte) (b & 0x7F);
		if (b == 0) {
			return Tag.Indefinite_Length;
		}

		// If bit 8 of the first length octet is set to 1, then we have the long
		// form of length. In long form, the first
		// octet encodes in its remaining seven bits a value N which is the
		// length of a series of octets that themselves
		// encode the length of the Value part.
		byte temp;
		for (int i = 0; i < b; i++) {
			temp = (byte) this.read();
			length = (length << 8) | (0x00FF & temp);
		}

		return length;
	}
452936
protected function getValueLength()
    {
        if ($this->maxlength_ignored_characters != '') {
            $chars = preg_quote($this->maxlength_ignored_characters, '/');
            $pattern = sprintf('/[%s]/u', $chars);
            $value = preg_replace($pattern, '', $this->value);
            $length = mb_strlen($value);
        } else {
            $length = mb_strlen($this->value);
        }
        return $length;
    }
436749
private function parseSignedInt16()
    {
        try {
            $result = \unpack('n', $this->buffer)[1];

            if ($result & 0x8000) {
                return $result - 0x10000;
            }

            return $result;
        } finally {
            $this->buffer = mb_orig_substr($this->buffer, 2);
        }
    }
1173687
private int parseChar()
        throws IOException
    {
        while (_chunkLength <= 0) {
            if (_isLastChunk)
                return -1;

            int code = read();

            switch (code) {
                case 's':
                case 'x':
                    _isLastChunk = false;

                    _chunkLength = (read() << 8) + read();
                    break;

                case 'S':
                case 'X':
                    _isLastChunk = true;

                    _chunkLength = (read() << 8) + read();
                    break;

                default:
                    throw expect("string", code);
            }

        }

        _chunkLength--;

        return parseUTF8Char();
    }
1073433
public function getLength()
    {
        if (!$this->stub && !is_int($this->length)) {
            $this->length = strlen($this->data);
        }

        return $this->length;
    }
118037
public function readInt16Signed()
    {

        // Read the data into a string
        $string = $this->read(2);

        // For big endian we need to reverse the bytes
        if ($this->number_type == self::NUMBER_TYPE_BIGENDIAN) {
            $string = strrev($string);
        }

        $int = unpack('sint', $string);

        unset($string);

        return $int['int'];
    }
99863
def read_length_encoded_integer(self):
        
        c = self.read_uint8()
        if c == NULL_COLUMN:
            return None
        if c < UNSIGNED_CHAR_COLUMN:
            return c
        elif c == UNSIGNED_SHORT_COLUMN:
            return self.read_uint16()
        elif c == UNSIGNED_INT24_COLUMN:
            return self.read_uint24()
        elif c == UNSIGNED_INT64_COLUMN:
            return self.read_uint64()
404166
public function parseBinaryString()
    {
        $this->uniqueTable = array();
        $this->countObjects = 0;
        $this->stringSize = 0;
        $this->intSize = 0;
        $this->miscSize = 0;
        $this->objectRefs = 0;

        $this->writtenObjectCount = 0;
        $this->objectTable = array();
        $this->objectRefSize = 0;

        $this->offsets = array();

        // first, we read the trailer: 32 byte from the end
        $buff = substr($this->content, -32);

        if (strlen($buff) < 32) {
            throw new PListException('Error in PList format: content is less than at least necessary 32 bytes!');
        }

        $infos = unpack("x6/Coffset_size/Cobject_ref_size/x4/Nnumber_of_objects/x4/Ntop_object/x4/Ntable_offset", $buff);

        // after that, get the offset table
        $coded_offset_table = substr($this->content, $infos['table_offset'], $infos['number_of_objects'] * $infos['offset_size']);
        if (strlen($coded_offset_table) != $infos['number_of_objects'] * $infos['offset_size']) {
            throw IOException::readError("");
        }
        $this->countObjects = $infos['number_of_objects'];

        // decode offset table
        $formats = array("","C*","n*",null,"N*");
        if ($infos['offset_size'] == 3) {
            /* since PHP does not support parenthesis in pack/unpack expressions,
               "(H6)*" does not work and we have to work round this by repeating the
               expression as often as it fits in the string
             */
            $this->offsets = array(null);
            while ($coded_offset_table) {
                $str = unpack("H6", $coded_offset_table);
                $this->offsets[] = hexdec($str[1]);
                $coded_offset_table = substr($coded_offset_table, 3);
            }
        } else {
            $this->offsets = unpack($formats[$infos['offset_size']], $coded_offset_table);
        }

        $this->uniqueTable = array();
        $this->objectRefSize = $infos['object_ref_size'];

        $top = $this->readBinaryObjectAt($infos['top_object']+1);
        $this->add($top);
    }
1147935
protected function parseTar()
	{
		$tarLength = strlen( $this->content );																// Read Files from archive
		$mainOffset = 0;
		while( $mainOffset < $tarLength )
		{
			if(substr($this->content,$mainOffset,512) == str_repeat(chr(0),512))							// If we read a block of 512 nulls, we are at the end of the archive
				break;
			$fileName		= $this->parseNullPaddedString(substr($this->content,$mainOffset,100));			// Parse file name
			$fileMode		= substr($this->content,$mainOffset + 100,8);									// Parse the file mode
			$fileUid		= octdec(substr($this->content,$mainOffset + 108,8));							// Parse the file user ID
			$fileGid		= octdec(substr($this->content,$mainOffset + 116,8));							// Parse the file group ID
			$fileSize		= octdec(substr($this->content,$mainOffset + 124,12));							// Parse the file size
			$fileTime		= octdec(substr($this->content,$mainOffset + 136,12));							// Parse the file update time - unix timestamp format
			$fileChksum	= octdec(substr($this->content,$mainOffset + 148,6));								// Parse Checksum
			$fileUname		= $this->parseNullPaddedString(substr($this->content,$mainOffset + 265,32));	// Parse user name
			$fileGname		= $this->parseNullPaddedString(substr($this->content,$mainOffset + 297,32));	// Parse Group name
			if($this->computeUnsignedChecksum(substr($this->content,$mainOffset,512)) != $fileChksum)		// Make sure our file is valid
				return false;
			$filecontents		= substr($this->content,$mainOffset + 512,$fileSize);						// Parse File Contents
			if( $fileSize > 0 )
			{
				if(!$this->containsFile( $fileName ) )
				{
					$this->numFiles++;																		// Increment number of files
					$activeFile = &$this->files[];															// Create us a new file in our array
					$activeFile['name']			= $fileName;												// Asign Values
					$activeFile['mode']			= $fileMode;
					$activeFile['size']			= $fileSize;
					$activeFile['time']			= $fileTime;
					$activeFile['user_id']		= $fileUid;
					$activeFile['group_id']		= $fileGid;
					$activeFile['user_name']	= $fileUname;
					$activeFile['group_name']	= $fileGname;
					$activeFile['checksum']		= $fileChksum;
					$activeFile['file']			= $filecontents;
				}
			}
			else
			{
				if( !$this->containsFolder( $fileName ) )
				{
					$this->numFolders++;																	// Increment number of directories
					$activeDir = &$this->folders[];															// Create a new folder in our array
					$activeDir['name']			= $fileName;												// Assign values
					$activeDir['mode']			= $fileMode;
					$activeDir['time']			= $fileTime;
					$activeDir['user_id']		= $fileUid;
					$activeDir['group_id']		= $fileGid;
					$activeDir['user_name']		= $fileUname;
					$activeDir['group_name']	= $fileGname;
					$activeDir['checksum']		= $fileChksum;
				}
			}
			$mainOffset += 512 + ( ceil( $fileSize / 512 ) * 512 );												// Move our offset the number of blocks we have processed
		}
		return true;
	}
1111966
public function readPhpInt()
    {
        list(, $res) = unpack('N', $this->_rawread(4));
        if ($this->_is64bits) {
            $sres = sprintf("%u", $res);
            return (int)$sres;
        } else {
            return $res;
        }
    }
467863
public function readInt()
    {
        $str = $this->_fread(4);

        return  ord($str[0]) << 24 |
                ord($str[1]) << 16 |
                ord($str[2]) << 8  |
                ord($str[3]);
    }
692480
final public function readInt16LE()
    {
        if ($this->isBigEndian()) {
            return $this->fromInt16(strrev($this->read(2)));
        } else {
            return $this->fromInt16($this->read(2));
        }
    }
578736
public function read_longlong()
    {
        $this->bitcount = $this->bits = 0;

        list(, $hi, $lo) = unpack('N2', $this->rawread(8));
        $msb = self::getLongMSB($hi);

        if (empty($this->is64bits)) {
            if ($msb) {
                $hi = sprintf('%u', $hi);
            }
            if (self::getLongMSB($lo)) {
                $lo = sprintf('%u', $lo);
            }
        }

        return bcadd($this->is64bits && !$msb ? $hi << 32 : bcmul($hi, '4294967296', 0), $lo, 0);
    }
583233
private function decodeInteger()
    {
        $offsetOfE = strpos($this->source, "e", $this->offset);
        if (false === $offsetOfE) {
            throw new RuntimeException("Unterminated integer entity at offset $this->offset");
        }

        $currentOffset = $this->offset;
        if ("-" == $this->getChar($currentOffset)) {
            ++$currentOffset;
        }

        if ($offsetOfE === $currentOffset) {
            throw new RuntimeException("Empty integer entity at offset $this->offset");
        }

        while ($currentOffset < $offsetOfE) {
            if (!ctype_digit($this->getChar($currentOffset))) {
                throw new RuntimeException("Non-numeric character found in integer entity at offset $this->offset");
            }
            ++$currentOffset;
        }

        $value = substr($this->source, $this->offset, $offsetOfE - $this->offset);

        // One last check to make sure zero-padded integers don't slip by, as
        // they're not allowed per bencode specification.
        $absoluteValue = (string) abs($value);
        if (1 < strlen($absoluteValue) && "0" == $value[0]) {
            throw new RuntimeException("Illegal zero-padding found in integer entity at offset $this->offset");
        }

        $this->offset = $offsetOfE + 1;

        // The +0 auto-casts the chunk to either an integer or a float(in cases
        // where an integer would overrun the max limits of integer types)
        return $value + 0;
    }
875109
public function toBinary()
    {
        $name = bin2hex($this->name);

        $binValue = $this->getEncodedValueForProp($this->name, $this->value);

        $valueLen = strlen(bin2hex($binValue)) / 3;

        $binary = hex2bin(
            $this->dec2hex(strlen($name))
            .$this->dec2hex($valueLen)
            .$this->dec2hex($this->valueType)
            .$name
        );

        return $binary.$binValue;
    }