Skip to content

Commit

Permalink
trying to help mark
Browse files Browse the repository at this point in the history
  • Loading branch information
N6REJ committed Jul 31, 2024
1 parent f42b15d commit 22c6221
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 235 deletions.
2 changes: 2 additions & 0 deletions core/classes/actions/class.action.quickPick.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public function checkQuickpickJson()
// Get the creation time of the local file if it exists
if ( file_exists( $this->jsonFilePath ) ) {
$localFileCreationTime = filectime( $this->jsonFilePath );
} else {
$this->rebuildQuickpickJson();
}

// Get the creation time of the remote file
Expand Down
31 changes: 16 additions & 15 deletions core/classes/class.core.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,19 @@ public function unzip7zFile($filePath, $destination)
*/
public function getFileFromUrl(string $moduleUrl, string $filePath, $progressBar = false)
{

$fileSize = filesize( $filePath );
// Read and write in chunks to avoid memory overload
$bufferSize = 32768; // 32KB
$bytesRead = 0;

if ( $fileSize === false ) {
// Handle the error, e.g., log it and exit the function
Util::logError( 'Failed to get file size for ' . $filePath );

return;
}

// Open the URL for reading
$inputStream = @fopen( $moduleUrl, 'rb' );
if ( $inputStream === false ) {
Expand All @@ -563,26 +576,14 @@ public function getFileFromUrl(string $moduleUrl, string $filePath, $progressBar
return ['error' => 'Error saving module'];
}

// Ensure $inputStream is a valid file resource
if ( is_resource( $inputStream ) ) {
// Get file statistics
$fileStats = fstat( $inputStream );
// Extract the file size
$fileSize = $fileStats['size'];
// Output the file size
Util::logError( 'File size: ' . $fileSize . ' bytes' );
}

// Read and write in chunks to avoid memory overload
$bufferSize = 32768; // 32KB
$steps = $fileSize / $bufferSize;
$bytesRead = 0;

while ( !feof( $inputStream ) ) {
$buffer = fread( $inputStream, $bufferSize );
fwrite( $outputStream, $buffer );
$bytesRead += strlen( $buffer );

// Start output buffering
ob_start();

// Send progress update
if ( $progressBar ) {
$progress = min( 100, ($bytesRead / $fileSize) * 100 );
Expand Down
Loading

0 comments on commit 22c6221

Please sign in to comment.