我使用zlib从这里用delphi压缩了一些文件 http://docwiki.embarcadero.com/CodeExamples/Berlin/en/ZLibCompressDecompress_(Delphi)
来自链接的var
LInput, LOutput: TFileStream;
LZip: TZCompressionStream;
begin
{ Create the Input, Output, and Compressed streams. }
LInput := TFileStream.Create(Edit1.Text, fmOpenRead);
LOutput := TFileStream.Create(Edit2.Text + '.zip', fmCreate);
LZip := TZCompressionStream.Create(LOutput, zcDefault);
{ Compress data. }
LZip.CopyFrom(LInput, LInput.Size);
{ Free the streams. }
LZip.Free;
LInput.Free;
LOutput.Free;
但是当尝试用xcode / ios解压缩时,我没有错误,但解压缩的数据不一样?
inp是输入nsdata
z_stream strm;
strm.zalloc=Z_NULL;
strm.zfree=Z_NULL;
strm.opaque=Z_NULL;
strm.total_out=0;
strm.next_in=(Bytef *)[inp bytes];
strm.avail_in=(uint)[inp length];
if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (15+16), 8, Z_DEFAULT_STRATEGY) != Z_OK) return nil;
NSMutableData *comp = [NSMutableData dataWithLength:16384];
do
{
if (strm.total_out>= [comp length]){ [comp increaseLengthBy:16384];}
strm.next_out=[comp mutableBytes] + strm.total_out;
strm.avail_out=(uint)[comp length] - (uint)strm.total_out;
deflate(&strm, Z_FINISH);
} while (strm.avail_out==0);
deflateEnd(&strm);
[comp setLength:strm.total_out];
有人有想法吗?
答案 0 :(得分:0)