兼容性仅测试通过在32位Autohotkey版本
GZIP_DecompressFile("test.txt", ret) MsgBox % ret GZIP_DecompressFile(file, ByRef ret, encoding:="utf-8"){ body := BinArr_FromFile(file) VarSetCapacity(data, size := body.MaxIndex() + 1) DllCall("oleaut32\SafeArrayAccessData", "ptr", ComObjValue(body), "ptr*", pdata) DllCall("RtlMoveMemory", "ptr", &data, "ptr", pdata, "ptr", size) DllCall("oleaut32\SafeArrayUnaccessData", "ptr", ComObjValue(body)) size := GZIP_DecompressBuffer(data, size) ret := StrGet(&data, size, encoding) } BinArr_FromFile(FileName) { oADO := ComObjCreate("ADODB.Stream") oADO.Type := 1 ; adTypeBinary oADO.Open oADO.LoadFromFile(FileName) return oADO.Read, oADO.Close } GZIP_DecompressBuffer( ByRef var, nSz ) { ; 'Microsoft GZIP Compression DLL' SKAN 20-Sep-2010 ; Decompress routine for 'no-name single file GZIP', available in process memory. ; Forum post : www.autohotkey.com/forum/viewtopic.php?p=384875#384875 ; Modified by Lexikos 25-Apr-2015 to accept the data size as a parameter. ; ---------- Added by tmplinshi ---------- static hModule, _ If !hModule { hModule := DllCall("LoadLibrary", "Str", "gzip.dll", "Ptr") _ := { base: {__Delete: "GZIP_DecompressBuffer"} } } If !_ Return DllCall("FreeLibrary", "Ptr", hModule) ; ---------- / Added by tmplinshi ---------- vSz := NumGet( var,nsz-4 ), VarSetCapacity( out,vsz,0 ) DllCall( "GZIP\InitDecompression" ) DllCall( "GZIP\CreateDecompression", UIntP,CTX, UInt,1 ) If ( DllCall( "GZIP\Decompress", UInt,CTX, UInt,&var, UInt,nsz, UInt,&Out, UInt,vsz , UIntP,input_used, UIntP,output_used ) = 0 && ( Ok := ( output_used = vsz ) ) ) VarSetCapacity( var,64 ), VarSetCapacity( var,0 ), VarSetCapacity( var,vsz,32 ) , DllCall( "RtlMoveMemory", UInt,&var, UInt,&out, UInt,vsz ) DllCall( "GZIP\DestroyDecompression", UInt,CTX ), DllCall( "GZIP\DeInitDecompression" ) Return Ok ? vsz : 0 } GZIP_CompressBuffer(ByRef var, nSz ){ static hModule, _ If !hModule { hModule := DllCall("LoadLibrary", "Str", "gzip.dll", "Ptr") _ := { base: {__Delete: "GZIP_CompressBuffer"} } } If !_ Return DllCall("FreeLibrary", "Ptr", hModule) vSz := NumGet( var,nsz-4 ), VarSetCapacity( out,vsz,0 ) DllCall( "GZIP\InitCompression" ) DllCall( "GZIP\CreateCompression", UIntP,CTX, UInt,1 ) If ( DllCall( "GZIP\Compress", UInt,CTX, UInt,&var, UInt,nsz, UInt,&Out, UInt,vsz , UIntP,input_used, UIntP,output_used ) = 0 && ( Ok := ( output_used = vsz ) ) ) VarSetCapacity( var,64 ), VarSetCapacity( var,0 ), VarSetCapacity( var,vsz,32 ) , DllCall( "RtlMoveMemory", UInt,&var, UInt,&out, UInt,vsz ) DllCall( "GZIP\DestroyCompression", UInt,CTX ), DllCall( "GZIP\DeInitCompression" ) Return Ok ? vsz : 0 }
49 queries in 1.354 seconds |