Blog
All Blog Posts | Next Post | Previous PostFree component to handle ZIP files in a TMS WEB Core application
Wednesday, August 5, 2020
Yesterday we introduced TWebQRCode as a free component to be used with TMS WEB Core. If you would like to work with ZIP files in a web application then we have good news for you! We created another free component: TWebZip.
TWebZip is a wrapper around the open source JSZip 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 Limitations page.
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;
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
WebZip1.ReadAsString('hello.txt', procedure(AFileName, AData: string) begin //process AData here end);
WebZip1.Remove('hello.txt'); //removes hello.txt from ZIP WebZip1.RemoveAll; //removes all of the files from the ZIP
WebZip1.Download('myzip.zip', zcStore); //no compression WebZip1.Download('myzip.zip', zcDeflateLevel1); //best speed WebZip1.Download('myzip.zip', zcDeflateLevel9); //best compression
procedure TForm1.WebZip1Progress(Sender: TObject; APercent: Single; ACurrentFile: string); begin WebProgressBar1.Position := Round(APercent); end;
If you would like to see how TWebZip works in practice, then head over to our demo 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 TMS WEB Core Partner program and you can download it from here.
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.
Tunde Keller
This blog post has received 5 comments.
2. Wednesday, February 17, 2021 at 2:56:39 PM
Hello,
My English is very bad.
How install this jszip.js in Delphi 10.3 ??
Thanx.
My English is very bad.
How install this jszip.js in Delphi 10.3 ??
Thanx.
den Braber J
3. Wednesday, February 17, 2021 at 3:57:14 PM
I have not TMSWEBCorePkgLibDXE13
I have TMSWEBCorePkgLibDXE12
What to do?
Thanx.
I have TMSWEBCorePkgLibDXE12
What to do?
Thanx.
den Braber J
4. Wednesday, February 17, 2021 at 9:26:16 PM
Replace the dependency in JSZip.dproj to the version of TMSWEBCorePkgLibDX** that you are using.
Bruno Fierens
5. Thursday, February 18, 2021 at 9:36:19 AM
It works now.
Greatz!!
Thanx.!!
Greatz!!
Thanx.!!
den Braber J
All Blog Posts | Next Post | Previous Post
Price Rhett