Skip to content

Commit

Permalink
Const MAX_KEYS
Browse files Browse the repository at this point in the history
  • Loading branch information
fogelito committed Sep 18, 2023
1 parent c9e972e commit a4a19b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/Storage/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
abstract class Device
{
/**
* Max chunk size while transfering file from one device to another
* Max chunk size while transferring file from one device to another
*/
protected int $transferChunkSize = 20000000; //20 MB

/**
* Sets the maximum number of keys returned to the response. By default, the action returns up to 1,000 key names.
*/
protected const MAX_KEYS = 1000;

/**
* Set Transfer Chunk Size
*
Expand Down Expand Up @@ -275,7 +280,7 @@ abstract public function getPartitionTotalSpace(): float;
* @param string $continuationToken
* @return array<mixed>
*/
abstract public function getFiles(string $dir, int $keys = 1000, string $continuationToken = ''): array;
abstract public function getFiles(string $dir, int $keys = self::MAX_KEYS, string $continuationToken = ''): array;

/**
* Get the absolute path by resolving strings like ../, .., //, /\ and so on.
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/Device/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public function getPartitionTotalSpace(): float
* @param string $dir Directory to scan
* @return string[]
*/
public function getFiles(string $dir, int $keys = 1000, string $continuationToken = ''): array
public function getFiles(string $dir, int $keys = self::MAX_KEYS, string $continuationToken = ''): array
{
if (! (\str_ends_with($dir, DIRECTORY_SEPARATOR))) {
$dir .= DIRECTORY_SEPARATOR;
Expand Down
6 changes: 3 additions & 3 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ public function delete(string $path, bool $recursive = false): bool
*
* @throws Exception
*/
private function listObjects(string $prefix = '', int $maxKeys = 1000, string $continuationToken = ''): array
private function listObjects(string $prefix = '', int $maxKeys = self::MAX_KEYS, string $continuationToken = ''): array
{
if($maxKeys > 1000){
if($maxKeys > self::MAX_KEYS){
throw new Exception('max-keys limit is 1000');
}

Expand Down Expand Up @@ -671,7 +671,7 @@ public function getPartitionTotalSpace(): float
*
* @throws Exception
*/
public function getFiles(string $dir, int $keys = 1000, string $continuationToken = ''): array
public function getFiles(string $dir, int $keys = self::MAX_KEYS, string $continuationToken = ''): array
{
$data = $this->listObjects($dir, $keys, $continuationToken);

Expand Down

0 comments on commit a4a19b9

Please sign in to comment.