예제 #1
0
 protected function sendEntity(StreamInterface $stream, HttpRequest $request, $compress)
 {
     if (!$request->hasEntity()) {
         $stream->write("Content-Length: 0\r\n\r\n");
         return;
     }
     $buffer = new StringStream();
     try {
         if ($compress) {
             $body = new DeflateOutputStream($buffer, DeflateOutputStream::GZIP);
             $body->setCloseCascade(false);
         } else {
             $body = $buffer;
         }
         $request->getEntity()->send($body);
         $body->close();
         $stream->write(sprintf("Content-Length: %u\r\n\r\n", $buffer->tell()));
         $buffer->rewind();
         Stream::pipe($buffer, $stream);
     } finally {
         $buffer->close();
     }
 }
예제 #2
0
 /**
  * Add a ZIP archives file contents to the deployment.
  * 
  * @param string $file
  * @return Deployment
  * 
  * @throws \InvalidArgumentException When the given archive could not be found.
  * @throws \RuntimeException When the given archive could not be read.
  */
 public function addArchive($file)
 {
     if (!is_file($file)) {
         throw new \InvalidArgumentException(sprintf('Archive not found: "%s"', $file));
     }
     if (!is_readable($file)) {
         throw new \RuntimeException(sprintf('Archive not readable: "%s"', $file));
     }
     $zip = new \ZipArchive();
     $zip->open($file);
     try {
         for ($i = 0; $i < $zip->numFiles; $i++) {
             $stat = (array) $zip->statIndex($i);
             // This will skip empty files as well... need a better way to this eventually.
             if (empty($stat['size'])) {
                 continue;
             }
             $name = $zip->getNameIndex($i);
             // Cap memory at 256KB to allow for large deployments when necessary.
             $stream = new StringStream('', 262144);
             $resource = $zip->getStream($name);
             try {
                 while (!feof($resource)) {
                     $stream->write(fread($resource, 8192));
                 }
                 $stream->rewind();
             } finally {
                 @fclose($resource);
             }
             $this->resources[trim(str_replace('\\', '/', $name), '/')] = $stream;
         }
     } finally {
         @$zip->close();
     }
     return $this;
 }