? features-tar-issue-smerrill.patch
Index: features.export.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/features/features.export.inc,v
retrieving revision 1.1.2.38
diff -u -p -r1.1.2.38 features.export.inc
--- features.export.inc	14 Sep 2009 14:47:31 -0000	1.1.2.38
+++ features.export.inc	30 Sep 2009 17:03:29 -0000
@@ -169,11 +169,14 @@ function features_export_build_form_subm
       }
       $tar["{$module_name}/{$module_name}.$extension"] = $file_contents;
     }
-    $tar = features_tar_create($tar);
 
-    $header = function_exists('gzencode') ? 'Content-type: application/x-gzip' : 'Content-type: application/x-tar';
+    //$header = function_exists('gzencode') ? 'Content-type: application/x-gzip' : 'Content-type: application/x-tar';
+    $header = 'Content-type: application/x-tar';
     $filename = !empty($filename) ? $filename : $module_name;
-    $filename = function_exists('gzencode') ? "{$filename}.tgz" : "{$filename}.tar";
+    //$filename = function_exists('gzencode') ? "{$filename}.tgz" : "{$filename}.tar";
+    $filename = "{$filename}.tar";
+
+    $tar = features_tar_create($tar, $filename);
 
     drupal_set_header($header);
     drupal_set_header('Content-Disposition: attachment; filename="'. $filename .'"');
@@ -654,8 +657,26 @@ function features_export_info($info, $pa
  * @return
  *   A string of the tar file contents.
  */
-function features_tar_create($files) {
+function features_tar_create($files, $output_filename) {
   $tar = '';
+
+  // @TODO: Make a real configuration option
+  if(variable_get('features_use_pear_tar', TRUE) == TRUE) {
+    include('Archive/Tar.php');
+    if(class_exists('Archive_Tar')) {
+      $tar_archive_path = file_directory_temp() .'/'. time() . 'features-temp-output.tar';
+      $tar_archive = new Archive_Tar($tar_archive_path);
+      
+      foreach($files as $name => $contents) {
+        $result = $tar_archive->addString($name, $contents);
+      }
+      file_transfer($tar_archive_path, array(
+        'Content-Type: application/x-tar',
+        'Content-Disposition: attachment; filename="'. $output_filename .'"',
+      ));
+    }
+  }
+
   foreach ($files as $name => $contents) {
     $binary_data_first = pack("a100a8a8a8a12A12",
       $name,
@@ -687,9 +708,12 @@ function features_tar_create($files) {
       $tar .= pack("a512", $item);
     }
   }
+  
+  /*
   if (function_exists('gzencode')) {
     $tar = gzencode($tar);
   }
+  */
   return $tar;
 }
 
