# Use the G3ZIP Library

## Overview
The **G3ZIP** library provides high-performance compression and archive management services for G3Pix AxonASP applications. It enables developers to create, read, and manipulate ZIP archives directly on the server without external dependencies. The library supports adding files and folders, generating archives from dynamic text, and extracting content to the file system.

## Syntax
To instantiate the library, use the following syntax:
```asp
Dim zip
Set zip = Server.CreateObject("G3ZIP")
```
```javascript
var zip = Server.CreateObject("G3ZIP");
```

## Prerequisites
- **File System Permissions**: The AxonASP process must have read/write access to the paths where archives are created or extracted.
- **Path Resolution**: Relative paths are automatically resolved via `Server.MapPath` in a web context.

## How it Works
The G3ZIP object operates in two primary modes: **Read** and **Write**. 
- **Read Mode**: Initialized using the **Open** method. In this mode, you can inspect the archive content, retrieve file metadata, and extract files.
- **Write Mode**: Initialized using the **Create** method. In this mode, you can build a new archive by adding existing files, entire directory structures, or custom text strings as virtual files.

AxonASP exposes the ZIP library through a single `Server.CreateObject` ProgID. No additional compatibility aliases are implemented for this object.

The library ensures proper resource management by requiring a call to the **Close** method when operations are complete, which flushes buffers and releases file handles.

## API Reference

### Methods
- **AddFile**: Includes an existing file into the active archive.
- **AddFolder**: Recursively includes a directory and its contents into the active archive.
- **AddText**: Creates a virtual file in the archive from a string.
- **Close**: Finalizes the archive and releases system resources.
- **Create**: Initializes a new ZIP archive for writing.
- **ExtractAll**: Unpacks the entire archive to a specified directory.
- **ExtractFile**: Unpacks a single file from the archive.
- **GetInfo**: Retrieves technical metadata for a specific file within the archive.
- **List**: Returns an array of file names contained in the archive.
- **Open**: Opens an existing ZIP archive for reading.

### Properties
- **Count**: Returns the number of files currently in the archive (Read mode).
- **Mode**: Indicates if the object is in Read ("r") or Write ("w") mode.
- **Path**: Returns the full physical path of the active archive.

## Code Example
The following example demonstrates how to create a ZIP archive containing a physical file and a dynamic text file.

```asp
<%
Dim zip, success
Set zip = Server.CreateObject("G3ZIP")

' Initialize a new archive
If zip.Create("/downloads/package.zip") Then
    ' Add a physical file from the server
    zip.AddFile "/data/report.pdf", "report.pdf"
    
    ' Add dynamic content as a text file
    zip.AddText "readme.txt", "This archive was generated by AxonASP on " & Now()
    
    ' Finalize the archive
    zip.Close
    Response.Write "Archive created successfully."
Else
    Response.Write "Failed to create archive."
End If

Set zip = Nothing
%>
```
