Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Filesystem.php

function Filesystem::filesAreEqual

compare 2 files https://stackoverflow.com/questions/3060125/can-i-use-file-get-contents…

1 call to Filesystem::filesAreEqual()
Filesystem::safeCopy in vendor/composer/composer/src/Composer/Util/Filesystem.php
Copy file using stream_copy_to_stream to work around https://bugs.php.net/bug.php?id=6463

File

vendor/composer/composer/src/Composer/Util/Filesystem.php, line 942

Class

Filesystem
@author Jordi Boggiano <j.boggiano@seld.be> @author Johannes M. Schmitt <schmittjoh@gmail.com>

Namespace

Composer\Util

Code

private function filesAreEqual(string $a, string $b) : bool {
    // Check if filesize is different
    if (filesize($a) !== filesize($b)) {
        return false;
    }
    // Check if content is different
    $aHandle = fopen($a, 'rb');
    assert($aHandle !== false, 'Could not open "' . $a . '" for reading.');
    $bHandle = fopen($b, 'rb');
    assert($bHandle !== false, 'Could not open "' . $b . '" for reading.');
    $result = true;
    while (!feof($aHandle)) {
        if (fread($aHandle, 8192) !== fread($bHandle, 8192)) {
            $result = false;
            break;
        }
    }
    fclose($aHandle);
    fclose($bHandle);
    return $result;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal