The Zip class enables reading/writing/creating zip files. More...
The PRIMER JavaScript API provides many class constants, properties and methods. For Arup to
be able to extend and enhance the API in the future any constant, property or method names beginning with a lowercase
or uppercase letter are reserved.
If you need to add your own properties or methods to one of the existing classes then to avoid any potential future conflict you
should ensure that the name begins with either an underscore (_) or a dollar sign ($) or the name is prefixed with your
own unique identifier.
For example if company 'ABC' need to add a property called 'example' then to avoid any potential future conflict use one of:
| Name | Description |
| Zip.APPEND | Flag to open zip file for appending |
| Zip.READ | Flag to open zip file for reading |
| Zip.WRITE | Flag to open zip file for writing |
| Name | Type | Description |
| filename (read only) | string | Name of the zip file |
| mode (read only) | constant | Mode the zip file was opened with (Zip.READ, Zip.WRITE or Zip.APPEND) |
Detailed DescriptionThe Zip class provides functions to enable you to read, write and create zip files. The following simple example shows how to write a zip file and then read it again: |
Message("Creating zip file");
var z = new Zip("C:/temp/test.zip", Zip.WRITE);
z.AddFile("C:/temp/bpost.key", "bpost/bpost.key");
z.AddFile("C:/temp/door.key", "door/door.key");
z.AddFile("C:/temp/barrier.key", "other.key");
z.Close();
Message("Done");
var entry = 0;
Message("Reading zip file");
var z = new Zip("C:/temp/test.zip", Zip.READ);
while (true)
{
entry++;
Message("Entry "+entry);
var info = z.Information();
for (var x in info)
Message(" "+x+"="+info[x]);
z.ReadFile(entry+".txt");
if (!z.Next()) break;
}
z.Close();
Message("Done")
Constructornew Zip(filename[string], mode[constant])DescriptionCreate a new Zip object for reading/writing zip files. |
Filename of the zip file you want to read/write. If reading (Zip.READ) or appending (Zip.APPEND), the file must exist. If writing (Zip.WRITE) the file will be overwritten (if it exists).
The mode to open the file with. Can be Zip.READ, Zip.WRITE or Zip.APPEND.
ReturnsZip object Return typeZip |
ExampleTo create a new Zip object to read Zip file "/data/test/file.zip" var p = new Zip("/data/test/file.zip");
|
Details of functionsAddFile(filename[string], zipname[string])DescriptionAdd a file to the Zip file |
Name of the file you want to add to the zip file
Name to give the file in the zip file
ReturnsNo return value |
ExampleTo add file 'C:/temp/test.key' to Zip file z with zip name 'test.key': z.AddFile('C:/temp/test.key', 'test.key');
|
Close()DescriptionClose a Zip file |
No arguments
ReturnsNo return value |
ExampleTo close Zip file z: z.Close();
|
Information()DescriptionGets information for the current entry in the Zip file such as name, size etc |
No arguments
Returns |
Object with the following properties:
| Name | Type | Description |
| compressedSize | integer | Compressed size |
| crc | integer | Cyclic redundancy check |
| name | string | Filename |
| uncompressedSize | integer | Uncompressed size |
object
ExampleTo get the information: var info = z.Information(); for (var x in info) Println(x + '=' + info[x]);
|
Next()DescriptionGo to the next entry in the Zip file |
No arguments
Returnstrue if there is a next entry, false if there are no more entries Return typeBoolean |
ExampleTo go to the next entry in zip file z: var next = z.Next();
|
ReadFile(filename[string])DescriptionReads the current entry to a file from the Zip file |
Name of the file you want to create
ReturnsNo return value |
ExampleTo read the current entry in Zip file z to a file 'test.key': z.ReadFile('test.key');
|