Index: wp-includes/http.php
===================================================================
--- wp-includes/http.php	(revision 11867)
+++ wp-includes/http.php	(working copy)
@@ -382,6 +382,16 @@
 		return array('headers' => $theHeaders, 'body' => $theBody);
 	}
 
+	function processResponseFromFile($tempPointer) {
+		while ($line = fgets($tempPointer, 1024))
+			if ($line === "\r\n")
+				break;
+			else
+				$position += strlen($line);
+
+		return $position;
+	}
+
 	/**
 	 * Transform header string into an array.
 	 *
@@ -439,6 +449,12 @@
 		return array('response' => $response, 'headers' => $newheaders, 'cookies' => $cookies);
 	}
 
+	function processHeadersFromFile($tmpPointer, $headerEndPosition) {
+		fseek($tmpPointer, 0);
+		return WP_Http::processHeaders(fread($tmpPointer, $headerEndPosition));
+	}
+
+
 	/**
 	 * Takes the arguments for a ::request() and checks for the cookie array.
 	 *
@@ -706,17 +722,30 @@
 		}
 
 		$strResponse = '';
+		$responseTemp = tempnam('/tmp', 'resptmp');
+		$fp = fopen($responseTemp, 'w+');
 		while ( ! feof($handle) )
-			$strResponse .= fread($handle, 4096);
+			fwrite($fp, fread($handle, 4096));
 
 		fclose($handle);
 
 		if ( true === $secure_transport )
 			error_reporting($error_reporting);
 
-		$process = WP_Http::processResponse($strResponse);
-		$arrHeaders = WP_Http::processHeaders($process['headers']);
+		$responsePartPos = WP_Http::processResponseFromFile($fp);
+		$arrHeaders = WP_Http::processHeadersFromFile($fp, $responsePartPos);
 
+		$bodyTemp = tempnam('/tmp', 'bodytmp'); // todo: wp_tempnam
+		$fpBody = fopen($bodyTemp, 'w');
+		fseek($fp, $responsePartPos+2);
+
+		while (!feof($fp))
+			fwrite($fpBody, fread($fp, 1024));
+
+		fclose($fp);
+		fclose($fpBody);
+		unlink($responseTemp);
+
 		// Is the response code within the 400 range?
 		if ( (int) $arrHeaders['response']['code'] >= 400 && (int) $arrHeaders['response']['code'] < 500 )
 			return new WP_Error('http_request_failed', $arrHeaders['response']['code'] . ': ' . $arrHeaders['response']['message']);
@@ -732,12 +761,20 @@
 
 		// If the body was chunk encoded, then decode it.
 		if ( ! empty( $process['body'] ) && isset( $arrHeaders['headers']['transfer-encoding'] ) && 'chunked' == $arrHeaders['headers']['transfer-encoding'] )
-			$process['body'] = WP_Http::chunkTransferDecode($process['body']);
+      throw new exception('unimplemented');
+//      WP_Http::chunkTransferDecodeFromFile($fpBody);
 
 		if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($arrHeaders['headers']) )
-			$process['body'] = WP_Http_Encoding::decompress( $process['body'] );
+		{
+      WP_Http_Encoding::decompressFromFile($bodyTemp);
+			$bodyTemp .= '_dc';
+		}
+		
+		// backward compatibility
+		if (filesize($bodyTemp) < 1000000)
+			$bodyTemp = file_get_contents($bodyTemp);
 
-		return array('headers' => $arrHeaders['headers'], 'body' => $process['body'], 'response' => $arrHeaders['response'], 'cookies' => $arrHeaders['cookies']);
+		return array('headers' => $arrHeaders['headers'], 'body' => $bodyTemp, 'response' => $arrHeaders['response'], 'cookies' => $arrHeaders['cookies']);
 	}
 
 	/**
@@ -1810,6 +1847,17 @@
 		return $compressed;
 	}
 
+	function decompressFromFile($tempName) {
+		$gzfp = gzopen($tempName, 'r');
+		$fp = fopen($tempName .'_dc', 'w');
+
+		while (!gzeof($gzfp))
+			fwrite($fp, gzread($gzfp, 1024));
+
+		gzclose($gzfp);
+		fclose($fp);
+	}
+
 	/**
 	 * Decompression of deflated string while staying compatible with the majority of servers.
 	 *
Index: wp-admin/includes/file.php
===================================================================
--- wp-admin/includes/file.php	(revision 11867)
+++ wp-admin/includes/file.php	(working copy)
@@ -442,26 +442,19 @@
 	if ( ! $tmpfname )
 		return new WP_Error('http_no_file', __('Could not create Temporary file'));
 
-	$handle = @fopen($tmpfname, 'wb');
-	if ( ! $handle )
-		return new WP_Error('http_no_file', __('Could not create Temporary file'));
-
 	$response = wp_remote_get($url, array('timeout' => 60));
 
 	if ( is_wp_error($response) ) {
-		fclose($handle);
 		unlink($tmpfname);
 		return $response;
 	}
 
 	if ( $response['response']['code'] != '200' ){
-		fclose($handle);
 		unlink($tmpfname);
 		return new WP_Error('http_404', trim($response['response']['message']));
 	}
 
-	fwrite($handle, $response['body']);
-	fclose($handle);
+	rename($response['body'], $tmpfname);
 
 	return $tmpfname;
 }
@@ -481,9 +474,6 @@
 	if ( ! $wp_filesystem || !is_object($wp_filesystem) )
 		return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
 
-	// Unzip uses a lot of memory
-	@ini_set('memory_limit', '256M');
-
 	$fs =& $wp_filesystem;
 
 	require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
@@ -491,53 +481,31 @@
 	$archive = new PclZip($file);
 
 	// Is the archive valid?
-	if ( false == ($archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING)) )
+	if ( false == $archive->extract($to) )
 		return new WP_Error('incompatible_archive', __('Incompatible archive'), $archive->errorInfo(true));
 
-	if ( 0 == count($archive_files) )
-		return new WP_Error('empty_archive', __('Empty archive'));
-
-	$path = explode('/', untrailingslashit($to));
-	for ( $i = count($path); $i > 0; $i-- ) { //>0 = first element is empty allways for paths starting with '/'
-		$tmppath = implode('/', array_slice($path, 0, $i) );
-		if ( $fs->is_dir($tmppath) ) { //Found the highest folder that exists, Create from here(ie +1)
-			for ( $i = $i + 1; $i <= count($path); $i++ ) {
-				$tmppath = implode('/', array_slice($path, 0, $i) );
-				if ( ! $fs->mkdir($tmppath, FS_CHMOD_DIR) )
-					return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
-			}
-			break; //Exit main for loop
-		}
-	}
-
-	$to = trailingslashit($to);
-	foreach ($archive_files as $file) {
-		$path = $file['folder'] ? $file['filename'] : dirname($file['filename']);
-		$path = explode('/', $path);
-		for ( $i = count($path); $i >= 0; $i-- ) { //>=0 as the first element contains data
-			if ( empty($path[$i]) )
-				continue;
-			$tmppath = $to . implode('/', array_slice($path, 0, $i) );
-			if ( $fs->is_dir($tmppath) ) {//Found the highest folder that exists, Create from here
-				for ( $i = $i + 1; $i <= count($path); $i++ ) { //< count() no file component please.
-					$tmppath = $to . implode('/', array_slice($path, 0, $i) );
-					if ( ! $fs->is_dir($tmppath) && ! $fs->mkdir($tmppath, FS_CHMOD_DIR) )
-						return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath);
-				}
-				break; //Exit main for loop
-			}
-		}
-
-		// We've made sure the folders are there, so let's extract the file now:
-		if ( ! $file['folder'] ) {
-			if ( !$fs->put_contents( $to . $file['filename'], $file['content']) )
-				return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']);
-			$fs->chmod($to . $file['filename'], FS_CHMOD_FILE);
-		}
-	}
+	chmod_recursive(trailingslashit($to));
 	return true;
 }
 
+function chmod_recursive($dir)
+{
+	chmod($dir, FS_CHMOD_DIR);
+	$d = dir($dir);
+	
+	while (false !== ($entry = $d->read()))
+	{
+		if ($entry == '.' || $entry == '..')
+			continue;
+			
+		if (is_dir($dir .'/'. $entry))
+			chmod_recursive($dir .'/'. $entry);
+		elseif (is_file($dir .'/'. $entry))
+			chmod($dir .'/'. $entry, FS_CHMOD_FILE);
+	}	
+	$d->close();
+}
+
 /**
  * {@internal Missing Short Description}}
  *

