Check if two files are identical using Javascript, Typescript, or Php

Comparing two files with a programming language may be a bit tricky when the files are big, cause we may need a lot of time or processing power to check if the data is exactly the same. Normally, the best (fastest) way to approach this situation is to generate a hash for each one of the files and compare them. If both hashes are the same and also the file sizes match, we consider the files to be equal. The TurboDepot library FilesManager class has a method that does this comparison for us with the fastest algorithm possible. Let's see how we can compare any files we want in javascript, typescript, or PHP:

Test with PHP if two files are the same

Download the latest TurboCommons and TurboDepot phar files, place them on your project as dependencies and run the following code:

require 'path/to/your/dependencies/folder/turbocommons-php-X.X.X.phar';
require 'path/to/your/dependencies/folder/turbodepot-php-X.X.X.phar';

use org\turbodepot\src\main\php\managers\FilesManager;

$filesManager = new FilesManager();
$filesManager->isFileEqualTo('path/to/file1', 'path/to/file2');

isFileEqualTo() will return true if both files are valid and contain the same data.

Test with Javascript (node js) if two files are the same

Install the turbodepot dependency by executing the following command at the root of your project:

npm install turbodepot-node

And then run the following code:

const { FilesManager } = require('turbodepot-node');
let filesManager = new FilesManager();
filesManager.isFileEqualTo('path/to/file1', 'path/to/file2');

isFileEqualTo() will return true if both files are valid and contain the same data.

Test with Typescript (TS) if two files are the same

Install the turbodepot dependency by executing the following command at the root of your project:

npm install turbodepot-node

And then run the following code:

import { FilesManager } from 'turbodepot-node';
let filesManager = new FilesManager();
filesManager.isFileEqualTo('path/to/file1', 'path/to/file2');

isFileEqualTo() will return true if both files are valid and contain the same data.