Adds a file to a zip file.

Syntax

Result = SRP_Zip("AddFile", ZipHandle, FileName, Data, Compression = 6)

Returns

1 if successful, 0 if not.

Parameters

NameDescription
ZipHandle Handle to an opened zip file.
FileName Name of the added file within the zip file.
Data Contents of the added file.
Compression The compression level. Optional.

Remarks

Call this service to add a file to the zip file. This service requires that you pass the contents of the file. The Filename parameter is only used to name to file within the zip archive itself. 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, then pass the actual file contents into the Data parameter.

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 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 entries.

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
       SRP_Zip("AddFile", hZip, "Test\Images\MyImage.BMP", Data)
       SRP_Zip("AddFile", hZip, "Images\MyImage.BMP", Data)
       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
           SRP_Zip("AddFile", hZip, "Test.dat", Data)
           SRP_Zip("Close", hZip)
       end
   end
end
  • No labels