DEV Community

Ship Stack
Ship Stack

Posted on Originally published at youtu.be

Same File Size Does Not Mean Duplicate

Two files, same name, same size. Must be duplicates, right? I tested that assumption with a real Node.js run, and it failed. Full run in this Short: https://youtu.be/nrhOO58008Y

The test

I made two notes files with the same name and the same size: 1,920 bytes each. If size were a reliable duplicate check, these two would be the same file.

Then I hashed both with SHA-256 in Node.js. The hashes were different. Different hashes mean different content, so the files are not duplicates, even though the name and size match exactly.

Why size is not enough

Size is a count, not a fingerprint. Two files reach the same byte count in endless ways: swap two paragraphs, change a word for a longer one and trim elsewhere, or just have unrelated content that happens to add up the same. A hash reads every byte, so any change, anywhere, changes the result.

That is why real duplicate finders use size only as a first pass. Group files by size to skip the obvious non-duplicates cheaply, then hash only the groups that collide. Checking size first is fast; trusting size alone is wrong.

Watch the run

The real terminal output is in the Short: https://youtu.be/nrhOO58008Y (narration is AI-generated; the test output is from a real run). The full duplicate-finder build is here: https://youtu.be/SFwkTAPenzw

Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.

Top comments (0)