GithubHelp home page GithubHelp logo

yingshancool / lazarus_decompress_tar_bz2 Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 9 KB

Lazarus_decompress_tar_bz2 is an open source project written using Lazarus (Free Pascal IDE) and aims to provide a simple and efficient tool for decompressing files in tar.bz2 format. This project leverages relevant components and libraries in Lazarus.

Pascal 100.00%
decompress delphi lazarus pascal uncompress unzip

lazarus_decompress_tar_bz2's Introduction

Lazarus_decompress_tar_bz2

Lazarus_decompress_tar_bz2 is an open source project written using Lazarus (Free Pascal IDE) and aims to provide a simple and efficient tool for decompressing files in tar.bz2 format. This project leverages relevant components and libraries in Lazarus.

import the library

uses
  ...... bzip2stream, libtar;

register function on TForm1 Class

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure DecompressTar(FileName, OutputFileName: string);
    function DecompressBzip2(SourceFile, TargetFile: string): boolean;
  private

  public  

function a

function TForm1.DecompressBzip2(SourceFile, TargetFile: string): boolean;
var
  InFile: TFileStream;
  Decompressed: TDecompressBzip2Stream;
  OutFile: TFileStream;
  Buffer: Pointer;
  i: integer;
const
  buffersize = 8096;
begin
  Result := False;
  InFile := TFileStream.Create(SourceFile, fmOpenRead);
  try
    Decompressed := TDecompressBzip2Stream.Create(InFile);
    OutFile := TFileStream.Create(TargetFile, fmCreate);
    try
      GetMem(Buffer, BufferSize);
      repeat
        i := Decompressed.Read(buffer^, BufferSize);
        if i > 0 then
          OutFile.WriteBuffer(buffer^, i);
      until i < BufferSize;
      Result := True;
    finally
      Decompressed.Free;
      OutFile.Free;
    end;
  finally
    InFile.Free;
  end;
end; 

function b

procedure TForm1.DecompressTar(FileName, OutputFileName: string);
var
  TA: TTarArchive;
  DirRec: TTarDirRec;
begin
  TA := TTarArchive.Create(FileName);
  TA.Reset;

  while TA.FindNext(DirRec) do
  begin
    if (DirRec.FileType = ftDirectory) and not DirectoryExists(OutputFileName + ExtractFilePath(DirRec.Name)) then;
    begin
      ForceDirectories(OutputFileName + ExtractFilePath(DirRec.Name));
    end;

    TA.ReadFile(OutputFileName + DirRec.Name);
  end;


  TA.Free;
end;       

Usage example

procedure TForm1.Button1Click(Sender: TObject);
var
  InputFileName, OutputFileName: string;
begin
  // 输入和输出文件名
  InputFileName := 'Git-2.43.0-64-bit.tar.bz2';
  OutputFileName := 'decompressed_file.tar';

  DecompressBzip2(InputFileName, OutputFileName);

  if not DirectoryExists('./abc/') then
  begin
    CreateDir('./abc/');
  end;

  DecompressTar(OutputFileName, './abc/');
end;   

lazarus_decompress_tar_bz2's People

Contributors

yingshancool avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.