Adds a file to a zip file.
Syntax
Result = SRP_Zip_AddFile(ZipHandle, FileName, Data, Password, Compression)
Returns
1 if successful, 0 if not.
Parameters
ZipHandle Handle to an opened zip file.
FileName Name of the added file within the zip file.
Data Contents of the added file.
Password Added file's security password. Optional.
Compression The compression level. Optional.
Remarks
Call this routine to add a file to the zip file. This method requires that you pass the contents of the file. The Filename parameter is only used to name to file within the zip file. For instance, if you want to store OSFile.dat into the ZIP file as MyZipFile.dat, you must first load OSFile.dat into a variable using OSRead and call AddFile passing "MyZipFile.dat" as the FileName and passing the actual file contents via the Data parameter. You may optionally use the Password parameter to protect the added file.
The Compression parameter can be used to customize the level of compression. There are 10 levels of compression: 0-9. For no compression, pass 0. Compression 1 is the fastest of all compression levels but is also the least compressed. Compression 9 is the slowest and most compact compression level. The parameter, when omitted, defaults to -1, which tells the API to use the default compression level: level 6.
If a file already exists with the same name, then it will be replaced by the added file.
To include subdirectory information, just prefix it to the filename. For example, pass "Images\MyImage.BMP" instead of just "MyImage.BMP". Subdirectory information will distinguish similar file names. Using the same example, you can add both "Images\MyImage.BMP" and "MyImage.BMP" to a zip file, and they will both be included as separate entities.
Examples
// load an OS file into a variable and add it to a new zip file hZip = SRP_Zip_Create("C:\MyFile.zip") If hZip EQ 0 then Call Msg(@Window, SRP_Zip_GetLastError()) end else // notice how we can add the same data as 3 files with different subdirectories OSRead Data from "C:\sample.bmp" then rv = SRP_Zip_AddFile(hZip, "Test\Images\MyImage.BMP", Data) rv = SRP_Zip_AddFile(hZip, "Images\MyImage.BMP", Data) rv = SRP_Zip_AddFile(hZip, "MyImage.BMP", Data) end SRP_Zip_Close(hZip) end
// add a file whose contents come directly from a table Open "MY_TABLE" to hTable then Read Data from hTable, "TEST_DATA" then hZip = SRP_Zip_Create("C:\MyFile.zip") If hZip EQ 0 then Call Msg(@Window, SRP_Zip_GetLastError()) end else rv = SRP_Zip_AddFile(hZip, "Test.dat", Data) SRP_Zip_Close(hZip) end end end