마음의 안정을 찾기 위하여 - [Delphi] ZLib Multiple Files Compress/DeCompress (ZLib 라이브러리를 이용하여 여러개의 파일 압축/해제 하기)
2260780
454
315
관리자새글쓰기
태그위치로그방명록
별일없다의 생각
dawnsea's me2day/2010
색상(RGB)코드 추출기(Color...
Connection Generator/2010
최승호PD, '4대강 거짓말 검...
Green Monkey**/2010
Syng의 생각
syng's me2DAY/2010
천재 작곡가 윤일상이 기획,...
엘븐킹's Digital Factory/2010
[Delphi] ZLib Multiple Files Compress/DeCompress (ZLib 라이브러리를 이용하여 여러개의 파일 압축/해제 하기)
Delphi/Etc Tip | 2019/06/28 15:36

procedure CompressFiles(Files : TStrings; const Filename : String);
var
 infile, outfile, tmpFile : TFileStream;
 compr : TZCompressionStream;
 i,l : Integer;
 s : String;
begin
  If Files.Count > 0 Then Begin
    outFile := TFileStream.Create(Filename,fmCreate);

    Try
      { the number of files }
      l := Files.Count;
      outfile.Write(l,SizeOf(l));

      For i := 0 to Files.Count-1 Do Begin
        infile := TFileStream.Create(Files[i],fmOpenRead);
        Try
          { the original filename }
          s := ExtractFilename(Files[i]);
          l := Length(s);
          outfile.Write(l,SizeOf(l));
          outfile.Write(s[1],l);

          { the original filesize }
          l := infile.Size;
          outfile.Write(l,SizeOf(l));

          { compress and store the file temporary}
          tmpFile := TFileStream.Create('tmp',fmCreate);

          compr := TZCompressionStream.Create(tmpFile, zcMax);
          try
            compr.CopyFrom(infile,l);
          finally
            compr.Free;
            tmpFile.Free;
          end;

          { append the compressed file to the destination file }
          tmpFile := TFileStream.Create('tmp',fmOpenRead);
          try
            outfile.CopyFrom(tmpFile,0);
          finally
            tmpFile.Free;
          end;
        finally
          infile.Free;
        end;
      end;
    finally
      outfile.Free;
    end;
    DeleteFile('tmp');
  end;
end;


procedure DecompressFiles(const Filename, DestDirectory : String);
var
 dest,s : String;
 decompr : TZDecompressionStream;
 infile, outfile : TFilestream;
 i,l,c : Integer;
begin
  // IncludeTrailingPathDelimiter (D6/D7 only)
  dest := IncludeTrailingPathDelimiter(DestDirectory);

  infile := TFileStream.Create(Filename,fmOpenRead);
  try
    { number of files }
     infile.Read(c,SizeOf(c));
     for i := 1 to c do begin
       { read filename }
       infile.Read(l,SizeOf(l));
       SetLength(s,l);
       infile.Read(s[1],l);

       { read filesize }
       infile.Read(l,SizeOf(l));

       { decompress the files and store it }
       s := dest+s; //include the path

       outfile := TFileStream.Create(s,fmCreate);

       decompr := TZDecompressionStream.Create(infile);
       try
         outfile.CopyFrom(decompr,l);
       finally
         outfile.Free;
         decompr.Free;
       end;
     end;
   finally
     infile.Free;
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CompressFiles(Memo1.Lines,'dest.myzip');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  DecompressFiles('dest.myzip','C\');
end;

2019/06/28 15:36 2019/06/28 15:36
Article tag list Go to top
View Comment 0
Trackback URL :: 이 글에는 트랙백을 보낼 수 없습니다
 
 
 
 
: [1] ... [75][76][77][78][79][80][81][82][83] ... [936] :
«   2024/03   »
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
전체 (936)
출판 준비 (0)
My-Pro... (41)
사는 ... (517)
블로그... (22)
My Lib... (32)
게임 ... (23)
개발관... (3)
Smart ... (1)
Delphi (93)
C Builder (0)
Object... (0)
VC, MF... (10)
Window... (1)
Open API (3)
Visual... (0)
Java, JSP (2)
ASP.NET (0)
PHP (5)
Database (12)
리눅스 (29)
Windows (25)
Device... (1)
Embedded (1)
게임 ... (0)
Web Se... (2)
Web, S... (21)
잡다한... (6)
프로젝트 (0)
Personal (0)
대통령... (13)
Link (2)