예제 #1
0
 /**
  * @param NodeInterface $node
  *
  * @return LocalFile
  * @throws InvalidCompressionTypeException
  *
  */
 public function flow(NodeInterface $node)
 {
     if (!$node instanceof LocalFile) {
         throw new InvalidArgumentException("Node: {$node} should be an instance of LocalFile");
     }
     $factory = new CompressionFactory();
     $compressor = $factory->getCompressor($this->compression);
     $this->log(LogLevel::INFO, "Compressing file: '{file}' using '{compression}'", ['file' => $node, 'compression' => $this->compression]);
     return $compressor->compress($node, $this->options);
 }
예제 #2
0
 public function setUp()
 {
     $this->builder = m::mock(Builder::class)->makePartial();
     $this->compressionFactory = m::mock(CompressionFactory::class);
     $this->compressionFactory->shouldReceive('isCompression')->with('gzip')->andReturn(true);
     $this->compressionFactory->shouldReceive('isCompression')->with('zip')->andReturn(true);
     $this->compressionFactory->shouldReceive('isCompression')->andReturn(false);
     $this->findCompression = new FindCompression($this->compressionFactory);
     $this->findCompression->setBuilder($this->builder);
 }
예제 #3
0
 /**
  * Find the compression of a file
  *
  * @param LocalFileNodeInterface $file
  *
  * @return string
  */
 public function getCompression(LocalFileNodeInterface $file)
 {
     $cmd = "file --brief --uncompress --mime {$file->getPath()}";
     $process = $this->getProcess($cmd);
     $process->mustRun();
     $result = $process->getOutput();
     if (preg_match('/compressed-encoding=application\\/(?:x-)?(.+?);/i', $result, $matches)) {
         if ($this->factory->isCompression($matches[1])) {
             $this->log(LogLevel::DEBUG, "Found the compression for '{file}' as '{compression}'", ['file' => $file, 'compression' => $matches[1]]);
             return $matches[1];
         }
         return CompressionFactory::TYPE_UNKNOWN;
     }
     return CompressionFactory::TYPE_NONE;
 }
예제 #4
0
 public function testIsCompression()
 {
     static::assertTrue($this->factory->isCompression(Gzip::NAME));
     static::assertTrue($this->factory->isCompression(Zip::NAME));
     static::assertFalse($this->factory->isCompression('lzop'));
 }