sisong / HDiffPatch

a C\C++ library and command-line tools for Diff & Patch between binary files or directories(folder); cross-platform; runs fast; create small delta/differential; support large files and limit memory requires when diff & patch.
Other
1.52k stars 280 forks source link

option to show diffFile details only #365

Closed mgrinzPlayer closed 9 months ago

mgrinzPlayer commented 10 months ago

First, thank you for your work.

Currently, when I want to get some info from diffFile (without accessing old orig file), I would run something like this, but there's only oldDataSize:

>hpatchz.exe nul DIFF whatever
old : "nul"
diff: "DIFF-s64"
out : "whatever"
oldFile dataSize 0 != diffFile saved oldDataSize 8174338597 ERROR!

hpatchz time: 0.003 s

With this dirty patch:

Index: hpatchz.c
===================================================================
--- hpatchz.c
+++ hpatchz.c
@@ -1023,6 +1023,8 @@
 #endif
                 check(hpatch_FALSE,HPATCH_HDIFFINFO_ERROR,"is hdiff file? get diffInfo");
         }
+        printf("diffFile saved oldDataSize : %" PRIu64 "\ndiffFile saved newDataSize : %" PRIu64 "\ncompressType : %s\n",
+                diffInfo.oldDataSize,diffInfo.newDataSize,diffInfo.compressType);
         if (poldData->streamSize!=diffInfo.oldDataSize){
             LOG_ERR("oldFile dataSize %" PRIu64 " != diffFile saved oldDataSize %" PRIu64 " ERROR!\n",
                     poldData->streamSize,diffInfo.oldDataSize);

I can get all needed info without accessing old original file:

>hpatchz.exe nul DIFF whatever
old : "nul"
diff: "DIFF"
out : "whatever"
diffFile saved oldDataSize : 8174338597
diffFile saved newDataSize : 8175880030
compressType :
oldFile dataSize 0 != diffFile saved oldDataSize 8174338597 ERROR!

hpatchz time: 0.014 s
$ ./hpatchz.exe /dev/null DIFF whatever 2>/dev/null | grep "diffFile saved oldDataSize" | cut -d' ' -f5
8174338597

$ ./hpatchz.exe /dev/null DIFF whatever 2>/dev/null | grep "diffFile saved newDataSize" | cut -d' ' -f5
8175880030

I use those information to decide if additional step is needed:

It would be nice to get the information natively, maybe -i (or -diffinfo) switch hpatchz -diffinfo DIFF > prints all info hpatchz -diffinfo#oldsize DIFF > prints oldDataSize only (just number, in bytes) hpatchz -diffinfo#newsize DIFF > prints newDataSize only (just number, in bytes) hpatchz -diffinfo#compresstype DIFF > prints compress type hpatchz -diffinfo#neededmemory DIFF > required bytes of memory (patching+decompress) etc.

of course BSDIFF and VCDIFF will show: diffFile saved oldDataSize : unavailable

sisong commented 9 months ago

thanks @mgrinzPlayer I update cmdline, see option "-info diffFile"

mgrinzPlayer commented 9 months ago

Thank you very much. What about -info#oldsize diffFile -info#newsize diffFile (just number in bytes)? Do you think it is not needed?

It could be used with windows batch script (or unix scripts without the need of cut / awk / etc.)

for /f %A in ('hdiffzpatch.exe -info#oldsize diffFile') do set oldfilesize=%A
sisong commented 9 months ago

I have no plans to implement -info#* (just number in bytes), you can fork and add it by yourself.

mgrinzPlayer commented 9 months ago

OK. Thank you.