當前位置:首頁 » 文件管理 » zlib解壓字元串

zlib解壓字元串

發布時間: 2022-08-03 12:14:31

Ⅰ C++中如何調用zlib.dll進行解壓壓縮

1 准備工作。
下載zlib.dll。以及相關頭文件。將dll文件及頭文件加入工程。
2 壓縮:
調用函數compress.
形式為
int compress(Byte * dest, uLong* destLen, const Byte *source, ULONG sourceLen);
功能是將source指向的空間,長度為sourceLen的數據進行壓縮,壓縮數據儲存在dest中,長度由參數destLen返回。
如果壓縮出錯,返回對應錯誤號,否則返回0.

3解壓縮:
調用函數uncompress.
形式為
int uncompress(Byte * dest, uLong* destLen, const Byte *source, ULONG sourceLen);
功能是將source指向的空間,長度為sourceLen的數據進行解壓縮,解壓縮後的數據儲存在dest中,長度由參數destLen返回。
如果解壓縮出錯,返回對應錯誤號,否則返回0.

Ⅱ 請教delphi是否有壓縮和解壓字元串函數

有的,在zlib單元有
ZCompressStr:壓縮字元串,傳人字元串,返回TBytes;
ZDecompressStr:解壓字元串,傳人TBytes,返回字元串;
具體用法自己查一下

Ⅲ 如何使用Zlib解壓內存塊中的文件

1 准備工作。 下載zlib.dll。以及相關頭文件。將dll文件及頭文件加入工程。 2 壓縮: 調用函數compress. 形式為 int compress(Byte * dest, uLong* destLen, const Byte *source, ULONG sourceLen); 功能是將source指向的空間,長度為sourceLen的數據進行壓縮,壓縮數據儲存在dest中,長度由參數destLen返回。 如果壓縮出錯,返回對應錯誤號,否則返回0. 3解壓縮: 調用函數uncompress. 形式為 int uncompress(Byte * dest, uLong* destLen, const Byte *source, ULONG sourceLen); 功能是將source指向的空間,長度為sourceLen的數據進行解壓縮,解壓縮後的數據儲存在dest中,長度由參數destLen返回。 如果解壓縮出錯,返回對應錯誤號,否則返回0.

Ⅳ 是否能用delphi的zlib解壓java gzip壓縮的字元串

可以使用 delphi 與 java 完成數據壓縮還原的交通。
不管是 java還是 delphi,演算法都有現成的控制項,關鍵是要使用同樣的壓縮協議。請參考以下資料:
在Java與Delphi間交互實現Zlib壓縮演算法
http://blog.csdn.net/hexingyeyun/article/details/8678154

Ⅳ 關於zlib解壓多文件的問題。

急需各位高手的解答,在此謝過了~問題補充:麻煩能說明一下zlib庫里的比如,你可以先去掉文件IO的過程,只是對一個字元串進行壓縮/解壓,然後看看

Ⅵ nodejs zlib 怎麼把幾個壓縮過的文件解壓拼接

我請求管用所結束httpvar http = require("http"),
zlib = require("zlib");

function getGzipped(url, callback) {
// buffer to store the streamed decompression
var buffer = [];

http.get(url, function(res) {
// pipe the response into the gunzip to decompress
var gunzip = zlib.createGunzip();
res.pipe(gunzip);

gunzip.on('data', function(data) {
// decompression chunk ready, add it to the buffer
buffer.push(data.toString())

}).on("end", function() {
// response and decompression complete, join the buffer and return
callback(null, buffer.join(""));

}).on("error", function(e) {
callback(e);
})
}).on('error', function(e) {
callback(e)
});
}

getGzipped(url, function(err, data) {
console.log(data);
});

2. 嘗試添加encoding: null給傳遞給選項request避免載體轉換字元串並保持二進制緩沖區

3. 工作示例(使用節點請求模塊)gunzips響應function gunzipJSON(response){

var gunzip = zlib.createGunzip();
var json = "";

gunzip.on('data', function(data){
json += data.toString();
});

gunzip.on('end', function(){
parseJSON(json);
});

response.pipe(gunzip);
}

全碼:

4. 像@Iftah說設置encoding: null 完整例(少錯誤處理):request = require('request');
zlib = require('zlib');

request(url, {encoding: null}, function(err, response, body){

if(response.headers['content-encoding'] == 'gzip'){

zlib.gunzip(body, function(err, dezipped) {
callback(dezipped.toString());
}

} else {
callback(body);
}
});

Ⅶ C# zlib字元串解壓

MemoryStream ms = new MemoryStream(bytes)

//這樣的話ms有數據的
CopyStream(tempMs, outZStream);
//lz,你將tempMS賦值給了outZStream,不是ms賦值給outZStream啊
//因為MemoryStream tempMs = new MemoryStream();
//tempMs沒有數據,但ms有數據,你將沒有數據的tempMs賦值過去,outZStream當然是空的...

Ⅷ 用C語言簡單演示如何藉助zlib庫實現文件的壓縮和解壓縮

問題的根源在於這些網友對於字元串和位元組流的概念非常的模糊,對文本文件和二進制文件的區別常常模稜兩可,其實位元組流可以表示所有的數據,二進制文件才是任何文件的本質。位元組流是一個位元組接一個位元組,並沒有結束符號,所以需要給它一個長度信息。二進制文件是一個位元組接一個位元組,並沒有換行符之類的。文件壓縮的時候,可以通過源文件的長度自動計算緩沖區的長度,壓縮後寫入目標文件之前,需先保留源文件和目標數據的長度作為解壓縮的依據,參考如下代碼:#include #include #include int main(int argc, char* argv[]) { FILE* file; uLong flen; unsigned char* fbuf = NULL; uLong clen; unsigned char* cbuf = NULL; /* 通過命令行參數將srcfile文件的數據壓縮後存放到dstfile文件中 */ if(argc < 3) { printf("Usage: zcdemo srcfile dstfile\n"); return -1; } if((file = fopen(argv[1], "rb")) == NULL) { printf("Can\'t open %s!\n", argv[1]); return -1; } /* 裝載源文件數據到緩沖區 */ fseek(file, 0L, SEEK_END); /* 跳到文件末尾 */ flen = ftell(file); /* 獲取文件長度 */ fseek(file, 0L, SEEK_SET); if((fbuf = (unsigned char*)malloc(sizeof(unsigned char) * flen)) == NULL) { printf("No enough memory!\n"); fclose(file); return -1; } fread(fbuf, sizeof(unsigned char), flen, file); /* 壓縮數據 */ clen = compressBound(flen); if((cbuf = (unsigned char*)malloc(sizeof(unsigned char) * clen)) == NULL) { printf("No enough memory!\n"); fclose(file); return -1; } if(compress(cbuf, &clen, fbuf, flen) != Z_OK) { printf("Compress %s failed!\n", argv[1]); return -1; } fclose(file); if((file = fopen(argv[2], "wb")) == NULL) { printf("Can\'t create %s!\n", argv[2]); return -1; } /* 保存壓縮後的數據到目標文件 */ fwrite(&flen, sizeof(uLong), 1, file); /* 寫入源文件長度 */ fwrite(&clen, sizeof(uLong), 1, file); /* 寫入目標數據長度 */ fwrite(cbuf, sizeof(unsigned char), clen, file); fclose(file); free(fbuf); free(cbuf); return 0; }文件解壓縮的時候,可以通過保留信息得到緩沖區和數據流的大小,這樣解壓縮後直接保存即可,參考如下代碼:#include #include #include int main(int argc, char* argv[]) { FILE* file; uLong flen; unsigned char* fbuf = NULL; uLong ulen; unsigned char* ubuf = NULL; /* 通過命令行參數將srcfile文件的數據解壓縮後存放到dstfile文件中 */ if(argc < 3) { printf("Usage: zudemo srcfile dstfile\n"); return -1; } if((file = fopen(argv[1], "rb")) == NULL) { printf("Can\'t open %s!\n", argv[1]); return -1; } /* 裝載源文件數據到緩沖區 */ fread(&ulen, sizeof(uLong), 1, file); /* 獲取緩沖區大小 */ fread(&flen, sizeof(uLong), 1, file); /* 獲取數據流大小 */ if((fbuf = (unsigned char*)malloc(sizeof(unsigned char) * flen)) == NULL) { printf("No enough memory!\n"); fclose(file); return -1; } fread(fbuf, sizeof(unsigned char), flen, file); /* 解壓縮數據 */ if((ubuf = (unsigned char*)malloc(sizeof(unsigned char) * ulen)) == NULL) { printf("No enough memory!\n"); fclose(file); return -1; } if(uncompress(ubuf, &ulen, fbuf, flen) != Z_OK) { printf("Uncompress %s failed!\n", argv[1]); return -1; } fclose(file); if((file = fopen(argv[2], "wb")) == NULL) { printf("Can\'t create %s!\n", argv[2]); return -1; } /* 保存解壓縮後的數據到目標文件 */ fwrite(ubuf, sizeof(unsigned char), ulen, file); fclose(file); free(fbuf); free(ubuf); return 0; }

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:641
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:368
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:87
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:310
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:794
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:346
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:213
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:817
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:367
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:594