You are here

private function Archive_Tar::_tarRecToSize in Drupal 7

Convert Tar record size to actual size

Parameters

string $tar_size:

Return value

size of tar record in bytes

1 call to Archive_Tar::_tarRecToSize()
Archive_Tar::_readHeader in modules/system/system.tar.inc

File

modules/system/system.tar.inc, line 1826

Class

Archive_Tar

Code

private function _tarRecToSize($tar_size) {

  /*
   * First byte of size has a special meaning if bit 7 is set.
   *
   * Bit 7 indicates base-256 encoding if set.
   * Bit 6 is the sign bit.
   * Bits 5:0 are most significant value bits.
   */
  $ch = ord($tar_size[0]);
  if ($ch & 0x80) {

    // Full 12-bytes record is required.
    $rec_str = $tar_size . "\0";
    $size = $ch & 0x40 ? -1 : 0;
    $size = $size << 6 | $ch & 0x3f;
    for ($num_ch = 1; $num_ch < 12; ++$num_ch) {
      $size = $size * 256 + ord($rec_str[$num_ch]);
    }
    return $size;
  }
  else {
    return OctDec(trim($tar_size));
  }
}