2012-12-13 2 views
1

IdCompressZlib 구성 요소를 CBuilderXE, 과 함께 사용해야하지만 그 주제에 대한 설명서 나 예제를 찾지 못했습니다. 나는 실험을 통해 그것을 사용하려고 시도했다.CBuilderXE와 함께 IdCompressZlib 구성 요소를 사용하는 방법

누군가가 저의 구성 요소를 사용하는 방법이나 그러한 주제에 유용한 몇 가지 예를 게시 할 수 있습니까?

업데이트 : Belowe I가 errore을 제공 tryed하고있는 샘플 코드 -5 메소드 InflateStream가 호출 :

int err; 
String Fun = "[TestCompress] ", s1, zipString, strTest = "The 'zlib' compression library provides in-memory compression \ 
and decompression functions, including integrity checks of the uncompressed data. \ 
This version of the library supports only one compression method (deflation) \ 
but other algorithms will be added later and will have the same stream interface. "; 

TStringStream * inpStream = NULL, *outStream = NULL; 
TMemoryStream * stream1 = NULL, *stream2 = NULL; 

stream1 = new TMemoryStream(); 
stream2 = new TMemoryStream(); 

inpStream = new TStringStream(); 
outStream = new TStringStream(); 

inpStream->Clear(); 
inpStream->WriteString(strTest); 
stream1->LoadFromStream(inpStream); 
stream1->Position = 0; 

IdCompressorZLib1->InflateStream(stream1, stream2); 

outStream->Clear(); 
stream2->SaveToStream(outStream); 
zipString = outStream->DataString; 

MyLog(Fun + Format("Compress test: Compress size from [%d] to [%d]", 
     ARRAYOFCONST((strTest.Length(), zipString.Length())))); 
+0

무엇 정확하게에 문제가 있습니까? 지금까지 해보지 못한 것이 당신에게 효과가 없었던 것은 무엇입니까? 'TIdCompressorZLib'를 정확히 사용하려고합니까? –

+0

안녕하세요, 제 첫 번째 문제는 구성 요소에 대한 문서가 부족하므로 예제에서 많은 도움을 얻을 수 있습니다. 스트림 내에서 문자열을 압축하기 위해 간단한 테스트를했습니다. – enzo2

+0

마지막 시도는 다음과 같았으며 항상 InflateStream 메소드를 호출 할 때 ann 에러 Z_DATA_ERROR (-3)을가집니다. – enzo2

답변

1

당신은 간단한 문자열을 압축 해제 할 수 없습니다!
오류 : (-5) InflateStream 첫 번째 바이트 수는 다음과 같아야합니다. zlib: 78 01 or 78 9C or 78 DA
오류 : (-3) InflateStream은 처음부터 바이트 수 (78 01)를 찾았지만 길이는 일치하지 않습니다.
strTest의 첫 번째 바이트는 "Th"입니다.

는 debug 폴더 2 개 파일

test2.dat 및 TEST.DAT가 프로그램을 실행 한 후 RAD (2010 Indy10을 테스트) 다음 코드

void __fastcall TForm1::Button1Click(TObject *Sender) 
{ 

String strTest = "The 'zlib' compression library provides in-memory compression \ 
and decompression functions, including integrity checks of the uncompressed data. \ 
This version of the library supports only one compression method (deflation) \ 
but other algorithms will be added later and will have the same stream interface. "; 

TStringStream * inpStream = NULL; 
TMemoryStream * stream1 = NULL, *stream2 = NULL, *stream3 = NULL; 

stream1 = new TMemoryStream(); 
stream2 = new TMemoryStream(); 
stream3 = new TMemoryStream(); 

inpStream = new TStringStream(); 


inpStream->Clear(); 
inpStream->WriteString(strTest); 
stream1->LoadFromStream(inpStream); 
stream1->Position = 0; 

// first compress stream1 with Level 1 
IdCompressorZLib1->DeflateStream(stream1,stream2,1); 

stream2->SaveToFile("test.dat"); 
stream3->LoadFromFile("test.dat"); 
stream2->Position = 0; 
// Now decompress stream3 
IdCompressorZLib1->InflateStream(stream3,stream2); 
stream2->SaveToFile("test2.dat"); 

} 

으로 시도 몇 바이트 TEST.DAT

(크기 190) 몇 바이트 test2.dat

xUQnÃ0C¯Â¿¶@× ... (Hex 78 01 55 8F 51 6E C3 ...) 

(크기 306 당신 Belowe)

The 'zlib' compression library provides in-memory compression and dec ... 
+0

당신은 바로 moskito입니다. 나는 Inflate and Deflate 함수를 잘못된 순서로 사용했다. 매뉴얼이 부족하여 기능의 의미가 잘못 해석되었습니다. 탱크. – enzo2

+0

도와 드리겠습니다. 귀하의 회신에 감사드립니다. –

0

는 작업 샘플을 제안

에 대한 모두에게 감사를 찾을 수
void __fastcall TFormMain::btnTestIdCompressClick(TObject * Sender) 
{ 
    int err; 
    String Fun = "[TestIdCompress] ", s1, zipString, strTest = "The 'zlib' compression library provides in-memory compression \ 
    and decompression functions, including integrity checks of the uncompressed data. \ 
    This version of the library supports only one compression method (deflation) \ 
    but other algorithms will be added later and will have the same stream interface. "; 

    TStringStream * inpStream = NULL, *outStream = NULL; 
    TMemoryStream * stream1 = NULL, *stream2 = NULL; 

    try 
    { 
     MyLog("--------------------------------------"); 
     MyLog(Fun + Format("Original msg : size=[%d] data=[%s]", ARRAYOFCONST((strTest.Length(), strTest)))); 

     stream1 = new TMemoryStream(); 
     stream2 = new TMemoryStream(); 

     inpStream = new TStringStream(); 
     outStream = new TStringStream(); 

     inpStream->Clear(); 
     inpStream->WriteString(strTest); 
     stream1->LoadFromStream(inpStream); 
     stream1->Position = 0; 

     IdCompressorZLib1->DeflateStream(stream1, stream2, 1); 

     outStream->Clear(); 
     stream2->SaveToStream(outStream); 
     zipString = outStream->DataString; 

     MyLog("--------------------------------------"); 
     MyLog(Fun + Format("Compressed msg : size=[%d] data=[%s]", ARRAYOFCONST((zipString.Length(), zipString)))); 

     inpStream->Clear(); 
     inpStream->WriteString(zipString); 
     stream1->LoadFromStream(inpStream); 
     stream1->Position = 0; 

     stream2->Position = 0; 
     // Now decompress stream3 
     IdCompressorZLib1->InflateStream(stream1, stream2); 
     outStream->Clear(); 
     stream2->SaveToStream(outStream); 
     s1 = outStream->DataString; 
     MyLog("--------------------------------------"); 
     MyLog(Fun + Format("Decompressed msg : size=[%d] data=[%s]", ARRAYOFCONST((s1.Length(), s1)))); 

    } 
    __finally 
    { 
     if (stream1) 
     { 
      stream1->Clear(); 
      delete stream1; 
      stream1 = NULL; 
     } 
     if (stream2) 
     { 
      stream2->Clear(); 
      delete stream2; 
      stream2 = NULL; 
     } 
     if (inpStream) 
     { 
      inpStream->Clear(); 
      delete inpStream; 
      inpStream = NULL; 
     } 
     if (outStream) 
     { 
      outStream->Clear(); 
      delete outStream; 
      outStream = NULL; 
     } 
    } 

} 
관련 문제