bsdiff是一個差別包比較工具,能夠用來實現增量更新.css
下載地址:http://www.daemonology.net/bsdiffhtml
版本:macOS 10.12express
1.解壓下載的bsdiff-4.3.tar.gzapp
tar -zxvf bsdiff-4.3.tar.gzide
2.進入bsdiff-4.3目錄,在終端下執行構建工具
cd bsdiff-4.3測試
makespa
此時報錯: Makefile:13: *** missing separator. Stop..net
這是makefile文件的內容的格式不對,修改Makefile文件,修改後的文件內容以下:3d
CFLAGS += -O3 -lbz2 PREFIX ?= /usr/local INSTALL_PROGRAM ?= ${INSTALL} -c -s -m 555 INSTALL_MAN ?= ${INSTALL} -c -m 444 all: bsdiff bspatch bsdiff: bsdiff.c bspatch: bspatch.c install: ${INSTALL_PROGRAM} bsdiff bspatch ${PREFIX}/bin .ifndef WITHOUT_MAN ${INSTALL_MAN} bsdiff.1 bspatch.1 ${PREFIX}/man/man1 .endif
即.ifndef WITHOUT_MAN,.endi語句f前面加TAB鍵進行縮進
而後再執行make,此時又報錯:
bspatch.c:39:21: error: unknown type name 'u_char'; did you mean 'char'? static off_t offtin(u_char *buf) ^~~~~~ char bspatch.c:65:8: error: expected ';' after expression u_char header[32],buf[8]; ^ ; bspatch.c:65:2: error: use of undeclared identifier 'u_char'; did you mean 'putchar'? u_char header[32],buf[8]; ^~~~~~ putchar /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/stdio.h:261:6: note: 'putchar' declared here int putchar(int); ^ bspatch.c:65:9: error: use of undeclared identifier 'header' u_char header[32],buf[8]; ^ bspatch.c:65:20: error: use of undeclared identifier 'buf' u_char header[32],buf[8]; ^ bspatch.c:66:2: error: use of undeclared identifier 'u_char'; did you mean 'putchar'? u_char *old, *new; ^~~~~~ putchar /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/stdio.h:261:6: note: 'putchar' declared here int putchar(int); ^ bspatch.c:66:10: error: use of undeclared identifier 'old' u_char *old, *new; ^ bspatch.c:66:16: error: use of undeclared identifier 'new' u_char *old, *new; ^ bspatch.c:93:12: error: use of undeclared identifier 'header' if (fread(header, 1, 32, f) < 32) { ^ bspatch.c:100:13: error: use of undeclared identifier 'header' if (memcmp(header, "BSDIFF40", 8) != 0) ^ bspatch.c:104:19: error: use of undeclared identifier 'header' bzctrllen=offtin(header+8); ^ bspatch.c:105:19: error: use of undeclared identifier 'header' bzdatalen=offtin(header+16); ^ bspatch.c:106:17: error: use of undeclared identifier 'header' newsize=offtin(header+24); ^ bspatch.c:137:5: error: use of undeclared identifier 'old' ((old=malloc(oldsize+1))==NULL) || ^ bspatch.c:139:12: error: use of undeclared identifier 'old' (read(fd,old,oldsize)!=oldsize) || ^ bspatch.c:141:6: error: use of undeclared identifier 'new' if((new=malloc(newsize+1))==NULL) err(1,NULL); ^ bspatch.c:147:43: error: use of undeclared identifier 'buf' lenread = BZ2_bzRead(&cbz2err, cpfbz2, buf, 8); ^ bspatch.c:151:19: error: use of undeclared identifier 'buf' ctrl[i]=offtin(buf); ^ bspatch.c:159:42: error: use of undeclared identifier 'new' lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]); ^ fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated. make: *** [bspatch] Error 1
在bspatch.c文件中加入#include <sys/types.h>
而後再執行make命令,此時命令執行成功,會在當前目錄下生成bsdiff,bspatch文件
版本:15.04
在終端執行sudo apt-get install bsdiff,執行完成後能夠在/usr/bin目錄下找到bsdiff,bspatch文件
OpenSUSE
版本:SUSE 11 SP4
1.解壓下載的bsdiff-4.3.tar.gz
tar -zxvf bsdiff-4.3.tar.gz
2.進入bsdiff-4.3目錄,在終端下執行構建
cd bsdiff-4.3
make
此時報錯: Makefile:13: *** missing separator. Stop.
這是makefile文件的內容的格式不對,修改Makefile文件,修改後的文件內容以下:
CFLAGS += -O3 -lbz2
PREFIX ?= /usr/local INSTALL_PROGRAM ?= ${INSTALL} -c -s -m 555 INSTALL_MAN ?= ${INSTALL} -c -m 444 all: bsdiff bspatch bsdiff: bsdiff.c bspatch: bspatch.c install: ${INSTALL_PROGRAM} bsdiff bspatch ${PREFIX}/bin .ifndef WITHOUT_MAN ${INSTALL_MAN} bsdiff.1 bspatch.1 ${PREFIX}/man/man1 .endif
接着編譯,結果報錯,找不到 bzlib.h
頭文件,這是因爲bsdiff,bspatch依賴bzip2,下載bzip2,地址:http://www.bzip.org/downloads.html,而後執行如下命令
tar zxvf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make
sudo make install
而後再編譯bsdiff,出現如下信息:
修改Makefile, 修改後以下:
CC=gcc LDFLAGS= CFLAGS += -O3 -lbz2 PREFIX ?= /usr/local INSTALL_PROGRAM ?= cp INSTALL_MAN ?= cp all: bsdiff bspatch bsdiff: bsdiff.c $(CC) bsdiff.c $(CFLAGS) $(LDFLAGS) -o bsdiff bspatch: bspatch.c $(CC) bspatch.c $(CFLAGS) $(LDFLAGS) -o bspatch install: ${INSTALL_PROGRAM} bsdiff bspatch ${PREFIX}/bin ${INSTALL_MAN} bsdiff.1 bspatch.1 ${PREFIX}/man/man1
而後再編譯,安裝就能夠了
生成差別文件,經常使用於服務端生成差別包
bsdiff oldfile newfile patchfile
oldfile: 舊的文件
newfile:新的文件
patchfile:生成的差別文件
合併文件,經常使用於客戶端根據差別包合併生成新的文件
bspatch oldfile newfile2 patchfile
oldfile:舊的文件
newfile2:生成的新的文件
patchfile:差別文件
舉個例子,測試一下使用bsdiff進行增量更新
./bsdiff old.apk new.apk old-new.patch
./bspatch old.apk new2.apk old-new.patch
md5 new.apk
MD5 (new.apk) = fc8bdb15f80abef22eb25f9601063cf0
md5 new2.apk
MD5 (new2.apk) = fc8bdb15f80abef22eb25f9601063cf0
此時new.apk和new2.apk的md5值是一致的