Skip to content

Commit

Permalink
Merge pull request #594 from damijank/patch-1
Browse files Browse the repository at this point in the history
Implement ChecksumCalculator Interface
  • Loading branch information
nicolasmure authored Dec 13, 2018
2 parents 9c520a9 + cc83b7e commit 7a92aba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Gaufrette/Adapter/AzureBlobStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
*/
class AzureBlobStorage implements Adapter,
MetadataSupporter,
SizeCalculator
SizeCalculator,
ChecksumCalculator

{
/**
Expand Down Expand Up @@ -334,6 +335,26 @@ public function size($key)

}

/**
* {@inheritdoc}
*/
public function checksum($key)
{
$this->init();
list($containerName, $key) = $this->tokenizeKey($key);

try {
$properties = $this->blobProxy->getBlobProperties($containerName, $key);
$checksumBase64 = $properties->getProperties()->getContentMD5();

return \bin2hex(\base64_decode($checksumBase64, true));
} catch (ServiceException $e) {
$this->failIfContainerNotFound($e, sprintf('read content MD5 for key "%s"', $key), $containerName);

return false;
}
}

/**
* {@inheritdoc}
* @throws \RuntimeException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ public function shouldGetSize()
$this->assertEquals($contentSize, $this->filesystem->size($path));
}

/**
* @test
* @group functional
*/
public function shouldGetMd5Hash()
{
$path = $this->createUniqueContainerName('container') . '/foo';

$content = 'Some content';
$this->filesystem->write($path, $content);

$this->assertEquals(\md5($content), $this->filesystem->checksum($path));
}

/**
* @test
* @group functional
Expand Down

0 comments on commit 7a92aba

Please sign in to comment.