Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Split File into Chunks
Demonstrates how to split a file into chunks.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.FileAccess;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
fac: TFileAccess;
fileToSplit: string;
partPrefix: string;
partExtension: string;
maxChunkSize: Integer;
destDirPath: string;
begin
success := False;
fac := TFileAccess.Create;
// Any type of file may be split. It doesn't matter if it's
// a binary file or a text file.
fileToSplit := 'qa_data/hamlet.xml';
partPrefix := 'hamlet';
partExtension := 'part';
maxChunkSize := 50000;
destDirPath := 'qa_output';
// Splits hamlet.xml into hamlet1.part, hamlet2.part, ...
// Output files are written to the current working directory.
// Each chunk will be 50000 bytes except for the last which
// will be the remainder.
success := fac.SplitFile(fileToSplit,partPrefix,partExtension,maxChunkSize,destDirPath);
if (success = True) then
begin
WriteLn('Success.');
end
else
begin
WriteLn(fac.LastErrorText);
end;
fac.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.