You are here

function configuration_tar_create in Configuration Management 7

Tar creation function. Written by dmitrig01.

Parameters

$name: Filename of the file to be tarred.

$contents: String contents of the file.

Return value

A string of the tar file contents.

1 call to configuration_tar_create()
configuration_download_config in ./configuration.admin.inc
Download the entire configuration packaged up into zip file

File

./configuration.export.inc, line 310

Code

function configuration_tar_create($name, $contents) {
  $tar = '';
  $binary_data_first = pack("a100a8a8a8a12A12", $name, '100644 ', '   765 ', '   765 ', sprintf("%11s ", decoct(strlen($contents))), sprintf("%11s", decoct(REQUEST_TIME)));
  $binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", '', '', '', '', '', '', '', '', '', '');
  $checksum = 0;
  for ($i = 0; $i < 148; $i++) {
    $checksum += ord(substr($binary_data_first, $i, 1));
  }
  for ($i = 148; $i < 156; $i++) {
    $checksum += ord(' ');
  }
  for ($i = 156, $j = 0; $i < 512; $i++, $j++) {
    $checksum += ord(substr($binary_data_last, $j, 1));
  }
  $tar .= $binary_data_first;
  $tar .= pack("a8", sprintf("%6s ", decoct($checksum)));
  $tar .= $binary_data_last;
  $buffer = str_split($contents, 512);
  foreach ($buffer as $item) {
    $tar .= pack("a512", $item);
  }
  return $tar;
}