- Регистрация
- 9 Май 2015
- Сообщения
- 1,072
- Баллы
- 155
- Возраст
- 52


TWebZip is a wrapper around the open source library. JSZip makes it possible to create, read, modify and download ZIP files directly in a client application. For limitations of the library please check the .
Features of TWebZip
The supported data types are: string, base64 encoded string (via a parameter setting), TJSArrayBuffer and TBytes.
Drop the non-visual TWebZip component onto the form and you have an empty ZIP file already! You can also open a ZIP file, for example through a TWebFilePicker:
procedure TForm1.WebFilePicker1Change(Sender: TObject);
begin
if WebFilePicker1.Files.Count > 0 then
WebFilePicker1.Files[0].GetAsArrayBuffer;
end;
procedure TForm1.WebFilePicker1GetFileAsArrayBuffer(Sender: TObject; AFileIndex: Integer; ABuffer: TJSArrayBufferRecord);
begin
WebZip1.Open(ABuffer);
end;
procedure TForm1.WebZip1ZipLoaded(Sender: TObject);
begin
//This is the implementation of the OnZipLoaded event:
//here we know that the ZIP was successfully opened
//and we can proceed with related calculations/tasks
end;
To add files to the ZIP, use the Add method. The first parameter is the filename with extension and the second parameter is the data to be added to the file. Keep in mind that if your ZIP already contains a file with a given name then it will override the content.
WebZip1.Add('subfolder/sub.txt', 'I''m in a subfolder!'); //Add sub.txt in the 'subfolder' folder
WebZip1.Add('hello.txt', 'Hello World'); //Adds hello.txt to the ZIP and sets the content to 'Hello World'
WebZip1.Add('hello.txt', 'Hello ZIP'); //Overrides the content of hello.txt
To read the content of a file, use the ReadAsString, ReadAsArrayBuffer or ReadAsBytes method based on which data type you need for further processing. These methods are asynchronous. The first parameter is the filename you want to read and the second is the anonymous method for processing the data.
WebZip1.ReadAsString('hello.txt', procedure(AFileName, AData: string)
begin
//process AData here
end);
To remove files, use the Remove(FileName) or RemoveAll methods.
WebZip1.Remove('hello.txt'); //removes hello.txt from ZIP
WebZip1.RemoveAll; //removes all of the files from the ZIP
Download the ZIP you created or modified with different compression levels. More information on these levels can be found .
WebZip1.Download('myzip.zip', zcStore); //no compression
WebZip1.Download('myzip.zip', zcDeflateLevel1); //best speed
WebZip1.Download('myzip.zip', zcDeflateLevel9); //best compression
Follow your download progress by implementing the OnProgress event:
procedure TForm1.WebZip1Progress(Sender: TObject; APercent: Single; ACurrentFile: string);
begin
WebProgressBar1.Position := Round(APercent);
end;
There are also extra properties for: file count (TWebZip.FileCount), file names (TWebZip.FileName, TWebZip.FileNames) and file comments (TWebZip.FileComment).
If you would like to see how TWebZip works in practice, then head over to our where you can upload images (JPEG or ZIP containing JPEGs) and download their grayscale version in a ZIP file. As we mentioned at the beginning of this article, TWebZip is available for free through our and you can download it from .
To install, open, compile & install the package from the "Component Library Source" folder. This will install the design-time TWebZip component.
For use at runtime, make sure that the "Core Source" folder is in your TMS WEB Core specific library path that you can set via IDE Tools, Options, TMS Web, Library path.