Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if two files have the same content?

Tags:

I am using mocha/supertest/should.js to test REST Service

GET /files/<hash> returns file as stream.

How can I assert in should.js that file contents are the same?

it('should return file as stream', function (done) {     var writeStream = fs.createWriteStream('test/fixtures/tmp.json');          var req = api.get('/files/676dfg1430af3595');     req.on('end', function(){        var tmpBuf = fs.readFileSync('test/fixtures/tmp.json');        var testBuf = fs.readFileSync('test/fixtures/test.json');             // How to assert with should.js file contents are the same (tmpBuf == testBuf )        // ...             done();     }); }); 
like image 333
hellboy Avatar asked Sep 11 '14 08:09

hellboy


1 Answers

Surprisingly, no one has suggested Buffer.equals. That seems to be the fastest and simplest approach and has been around since v0.11.

So your code would become tmpBuf.equals(testBuf)

like image 54
Max Avatar answered Sep 17 '22 07:09

Max