2010-01-31 4 views

답변

4

해결책을 찾은 것 같습니다.

이것은 매우 조잡한 코드 샘플이지만 제대로 작동하는 것 같습니다.

전체 파일을 읽기 전용으로 메모리에 매핑하고 매핑 된 전체 크기를 반환하는 do_mmap() 함수가 있다고 가정합니다. 이것은 자연스럽게 read/fread/ReadFile 또는 다른 File API를 사용하도록 조정될 수 있습니다.

extern size_t get_uncompressed_size(const char *filename) 
{ 
    lzma_stream_flags stream_flags; 
    int file_size; 

    const uint8_t *data = (uint8_t *) do_mmap(filename, &file_size); 

    // 12 is the size of the footer per the file-spec... 
    const uint8_t *footer_ptr = data + file_size - 12; 

    // Something is terribly wrong 
    if (footer_ptr < data) { 
    do_unmap((void *)data, file_size); 
    return -1; 
    } 

    // Decode the footer, so we have the backward_size pointing to the index 
    lzma_stream_footer_decode(&stream_flags, (const uint8_t *)footer_ptr); 
    // This is the index pointer, where the size is ultimately stored... 
    const uint8_t *index_ptr = footer_ptr - stream_flags.backward_size; 
    // Allocate an index 
    lzma_index *index = lzma_index_init(NULL); 
    uint64_t memlimit; 
    size_t in_pos = 0; 
    // decode the index we calculated 
    lzma_index_buffer_decode(&index, &memlimit, NULL, index_ptr, &in_pos, footer_ptr - index_ptr); 
    // Just make sure the whole index was decoded, otherwise, we might be 
    // dealing with something utterly corrupt 
    if (in_pos != stream_flags.backward_size) { 
    do_unmap((void *)data, file_size); 
    lzma_index_end(index, NULL); 
    return -1; 
    } 
    // Finally get the size 
    lzma_vli uSize = lzma_index_uncompressed_size(index); 
    lzma_index_end(index, NULL); 
    return (size_t) uSize; 
} 
+0

내가 당신이 어떤 API 문서 또는이 codec.If 하둡 압축을 작성하는 기본 라이브러리 LZMA2 사용할 압축 알고리즘의 다양한 래퍼라고 생각합니다 압축/압축 해제 관련 도움말에 도움이 될 것입니다. – samarth

+0

두 가지 문제가 있습니다. (1)'lzma_index_buffer_decode'를 호출하기 전에'memlimit'을 초기화해야합니다. 어떤 경우에는'LZMA_MEMLIMIT_ERROR'를 리턴합니다. (2)'lzma_index_init'를 호출해서는 안됩니다. 'index'의 초기 값은'lzma_index_buffer_decode'에 의해 무시됩니다. – Patrick

0

sourceforge에서 소스를 다운로드하고 여기에보고했다 데, 나는 메인 헤더 파일 LzmaLib.h

 
/* 
LzmaUncompress 
-------------- 
In: 
    dest  - output data 
    destLen - output data size 
    src  - input data 
    srcLen - input data size 
Out: 
    destLen - processed output size 
    srcLen - processed input size 
Returns: 
    SZ_OK    - OK 
    SZ_ERROR_DATA  - Data error 
    SZ_ERROR_MEM   - Memory allocation arror 
    SZ_ERROR_UNSUPPORTED - Unsupported properties 
    SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src) 
*/ 

MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen, 
    const unsigned char *props, size_t propsSize); 

그것은 destLen는 압축되지 않은 데이터의 크기 것으로 보인다에서이를 인용했다.

호프가 도움이 되었으면 안녕하세요, 탐.

+1

은 내가 XZ 파일 형식이 아닌 직선 LZMA, 오히려 –