Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare two version of files and apply changes to older file

I've been searching & googling a lot about this question, and I already know how to compare two files (hashes, checksums, etc.). But it's not quite what I need. What I need is described below.

Lets assume I have a file and I've backuped it. Later I've made some changes to this file, so I want to apply changes to the backup version. Since two files can be big enought and changes can be small, I don't want to rewrite all the file, because I'm planning to backup it though the internet (maybe FTP) wich can take a lot of time.

How I see this (sample):

Backup version of file (bytes)

134 253 637 151

Newer version of file (bytes)

134 624 151 890

Instead of rewriting all bytes, we should:

  1. change 253 to 624 (change bytes)
  2. remove 637 bytes (remove bytes)
  3. write 890 at the end of file (insert bytes)

The 1,2,3 options do not necessarily appear at once in each case. Note that the backup file could be located somewhere else, and I only have acces to it through the internet (server could return something so we can compare files).

How can I achive this? I know it's possible cause I know software where it's implemented (but couldn't find out how). Any hints, tutorials, etc. is welcomed and highly appriciated. Thanks in advance.

like image 820
GaaRa Avatar asked Feb 21 '23 03:02

GaaRa


1 Answers

You're trying to solve the same problem that every MMORPG has solved... creating and applying small patch files to update older versions of large binaries.

This is a well-studied problem and there are a number of solutions out there. For several existing options, see

Binary patch-generation in C#

like image 150
Eric J. Avatar answered May 09 '23 02:05

Eric J.