user2422940
user2422940

Reputation: 977

how to check if two files are the same?

I would like to know if there is a ways of telling that two files are the same ?

I am using a solution but it appeared that it is not very effective, i download the first part of each one than i convert the data received into base64 and finally i compare between them.

but i face a problem when for example the first half of both files (a.html and b.html) are the same, the signature that is generated is the same even if the last part is different. the code i use to download a preview of the file

https.get(url, function(res) {
        var chunks = [];
        if (res.statusCode !== 200) {
            responce.jsonp(404, null);
        }
        res.on('data', function(chunk) {

            chunks.push(chunk);
            var jsfile = new Buffer.concat(chunks).toString('base64');
            jsfile = jsfile.substring(0, 100);
            responce.header('Access-Control-Allow-Origin', '*');
            responce.header('Access-Control-Allow-Headers', 'X-Requested-With');
            responce.header('content-type', 'application/pdf');
            responce.send(200, jsfile);
        });

Upvotes: 0

Views: 3673

Answers (1)

Le Trong
Le Trong

Reputation: 144

I think you should use md5 hash for files compare. Check this out : node.js hash string?

Upvotes: 1

Related Questions