当前位置:首页 » 文件管理 » 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 浏览:642
荣耀x10从哪里设置密码 发布:2025-04-16 17:11:43 浏览:368
java从入门到精通视频 发布:2025-04-16 17:11:43 浏览:88
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 浏览:818
proteus编译文件位置 发布:2025-04-16 16:18:44 浏览:367
土压缩的本质 发布:2025-04-16 16:13:21 浏览:594