You are here

function _custom_formatters_tar_create in Custom Formatters 6

Tar creation function. Written by dmitrig01. Taken from the Features module.

Parameters

$files: A keyed array where the key is the filepath and the value is the string contents of the file.

Return value

A string of the tar file contents.

1 call to _custom_formatters_tar_create()
custom_formatters_formatter_export_tar in ./custom_formatters.admin.inc

File

./custom_formatters.admin.inc, line 630
Contains administration functions for the Custom Formatters module.

Code

function _custom_formatters_tar_create($files) {
  $tar = '';
  foreach ($files as $name => $contents) {
    $binary_data_first = pack("a100a8a8a8a12A12", $name, '100644 ', '   765 ', '   765 ', sprintf("%11s ", decoct(strlen($contents))), sprintf("%11s", decoct(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);
    }
  }
  if (function_exists('gzencode')) {
    $tar = gzencode($tar);
  }
  return $tar;
}