Skip to main content
本文に 2066 文字追加
ソース リンク
user3732298
  • 969
  • 8
  • 24
  • 39

■追記(Zlib 使用)

#import <Foundation/Foundation.h>
#include <zlib.h>


extern "C"{
    void uncompressByGzip(const char** ptrSrc, const int srcLength);
}


void uncompressByGzip(const char** ptrSrc, const int srcLength)
{
    NSData *source = [NSData dataWithBytes:(const void *)ptrSrc length:(sizeof(unsigned char) * srcLength)];

    NSString* str = [NSString stringWithFormat:@"%d",srcLength];
    NSLog(@"src = %@",str);
    if (source.length == 0)
        return;
    NSLog(@"11111");

    z_stream stream;
    stream.zalloc = Z_NULL;
    stream.zfree = Z_NULL;
    stream.opaque = Z_NULL;
    stream.avail_in = (uInt)source.length;
    stream.next_in = (Bytef *)source.bytes;
    stream.total_out = 0;
    stream.avail_out = 0;
    
    NSLog(@"22222");
    if (inflateInit2(&stream, 31) != Z_OK)
        return;

    NSLog(@"33333");
    NSMutableData *FileSystemData = [NSMutableData dataWithCapacity:0];
    while (stream.avail_out == 0) {
        NSLog(@"12345");
        Bytef buffer[16384];
        stream.next_out = buffer;
        stream.avail_out = sizeof(buffer);
        NSString* avail_outbef = [NSString stringWithFormat:@"%d",(NSInteger)stream.avail_out];
        NSLog(@"avail_outbef = %@",avail_outbef);
    
//        inflate(&stream, Z_FINISH);
        inflate(&stream,Z_NO_FLUSH);
        size_t length = sizeof(buffer) - stream.avail_out;
    
        avail_outbef = [NSString stringWithFormat:@"%d",(NSInteger)stream.avail_out];
        NSLog(@"avail_outaft = %@",avail_outbef);
    
        NSString* strlength = [NSString stringWithFormat:@"%d",(NSInteger)length];
        NSLog(@"length = %@",strlength);
    
        if (length > 0)
            [FileSystemData appendBytes:buffer length:length];
    }
    inflateEnd(&stream);
    NSLog(@"44444");
}

■追記(Zlib 使用)

#import <Foundation/Foundation.h>
#include <zlib.h>


extern "C"{
    void uncompressByGzip(const char** ptrSrc, const int srcLength);
}


void uncompressByGzip(const char** ptrSrc, const int srcLength)
{
    NSData *source = [NSData dataWithBytes:(const void *)ptrSrc length:(sizeof(unsigned char) * srcLength)];

    NSString* str = [NSString stringWithFormat:@"%d",srcLength];
    NSLog(@"src = %@",str);
    if (source.length == 0)
        return;
    NSLog(@"11111");

    z_stream stream;
    stream.zalloc = Z_NULL;
    stream.zfree = Z_NULL;
    stream.opaque = Z_NULL;
    stream.avail_in = (uInt)source.length;
    stream.next_in = (Bytef *)source.bytes;
    stream.total_out = 0;
    stream.avail_out = 0;
    
    NSLog(@"22222");
    if (inflateInit2(&stream, 31) != Z_OK)
        return;

    NSLog(@"33333");
    NSMutableData *FileSystemData = [NSMutableData dataWithCapacity:0];
    while (stream.avail_out == 0) {
        NSLog(@"12345");
        Bytef buffer[16384];
        stream.next_out = buffer;
        stream.avail_out = sizeof(buffer);
        NSString* avail_outbef = [NSString stringWithFormat:@"%d",(NSInteger)stream.avail_out];
        NSLog(@"avail_outbef = %@",avail_outbef);
    
//        inflate(&stream, Z_FINISH);
        inflate(&stream,Z_NO_FLUSH);
        size_t length = sizeof(buffer) - stream.avail_out;
    
        avail_outbef = [NSString stringWithFormat:@"%d",(NSInteger)stream.avail_out];
        NSLog(@"avail_outaft = %@",avail_outbef);
    
        NSString* strlength = [NSString stringWithFormat:@"%d",(NSInteger)length];
        NSLog(@"length = %@",strlength);
    
        if (length > 0)
            [FileSystemData appendBytes:buffer length:length];
    }
    inflateEnd(&stream);
    NSLog(@"44444");
}
タイトルを編集
リンク
user3732298
  • 969
  • 8
  • 24
  • 39

C++かObjective-cでByte配列からByte配列にZip解凍したい

ソース リンク
user3732298
  • 969
  • 8
  • 24
  • 39

C++かObjective-cでByte配列からByte配列に解凍したい

C#側でtarからZipをMemoryStreamに取り出すことができたので、
これをiOS側に渡してC++かobejective-cでunzipして、
unzipしたものをbyte配列もしくはStreamで持ちたいのですが、
C++かobejective-cでZipのByte配列をUnZipしてByte配列に変換する方法、
もしくはライブラリはないでしょうか?

まだObejective-c側しか調査してないのですが、
SSZipArchiveやObjectiveZipというものを見つけたのですが
ファイル名を与えないと解凍できないようでして、
C#のZipInputStreamのようなものがなく悩んでおります。

●SSZipArchive
https://github.com/soffes/ssziparchive
●ObjectiveZip
https://github.com/gianlucabertani/Objective-Zip