Delphi zlib / iOS不兼容?

时间:2016-08-09 15:20:30

标签: ios delphi zlib

我使用zlib从这里用delphi压缩了一些文件 http://docwiki.embarcadero.com/CodeExamples/Berlin/en/ZLibCompressDecompress_(Delphi)

来自链接的

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解压缩时,我没有错误,但解压缩的数据不一样?

xcode zlib

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];

有人有想法吗?

1 个答案:

答案 0 :(得分:0)

好吧,几天之后,然后答案很简单,我想解压缩文件我用delphi压缩,所以使用了错误的程序;-) 需要使用INFLATE而不是deflate(压缩)