Commit 7e2020be authored by Mihail Geshoski's avatar Mihail Geshoski Committed by Jenkins
Browse files

MDL-65115 core_files: Add get_total_content_size() in stored_file class

New function get_total_content_size() is introduced in the stored_file
class. The puprose of this function is to calculate and return the
total size (in bytes) of the content of an archive file.
parent 4b20cc22
......@@ -496,6 +496,27 @@ class stored_file {
return $this->filesystem->list_files($this, $packer);
}
/**
* Returns the total size (in bytes) of the contents of an archive.
*
* @param file_packer $packer file packer instance
* @return int|null total size in bytes
*/
public function get_total_content_size(file_packer $packer): ?int {
// Fetch the contents of the archive.
$files = $this->list_files($packer);
// Early return if the value of $files is not of type array.
// This can happen when the utility class is unable to open or read the contents of the archive.
if (!is_array($files)) {
return null;
}
return array_reduce($files, function ($contentsize, $file) {
return $contentsize + $file->size;
}, 0);
}
/**
* Extract file to given file path (real OS filesystem), existing files are overwritten.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment