Using RingZip

In this chapter we will learn about using RingZip

Create Zip File

Example : Create myfile.zip contains 4 files

load "ziplib.ring"
oZip = zip_openfile("myfile.zip",'w')
zip_addfile(oZip,"test.c")
zip_addfile(oZip,"zip.c")
zip_addfile(oZip,"zip.h")
zip_addfile(oZip,"miniz.h")
zip_close(oZip)

Extract Zip File

Example : Extract myfile.zip to myfolder folder.

load "ziplib.ring"
zip_extract_allfiles("myfile.zip","myfolder")

Using RingZip Classes

The RingZip library comes with two classes. The Zip class and the ZipEntry class.

Example (1):

load "ziplib.ring"

new Zip {
        setFileName("myfile.zip")
        open("w")
        newEntry() {
                open("test.c")
                writefile("test.c")
                close()
        }
        close()
}

Example (2):

load "ziplib.ring"

new Zip {
        SetFileName("myfile.zip")
        Open("w")
        AddFile("test.c")
        AddFile("zip.c")
        AddFile("zip.h")
        AddFile("miniz.h")
        Close()
}

Example (3):

load "ziplib.ring"

new zip {
        SetFileName("myfile.zip")
        ExtractAllFiles("myfolder")
}

Example (4):

load "ziplib.ring"

new Zip {
        SetFileName("myfile.zip")
        Open("r")
        see FilesCount()
        Close()
}

Example (5):

load "ziplib.ring"

new Zip {
        SetFileName("myfile.zip")
        Open("r")
        for x = 1 to filescount()
                See GetFileNameByIndex(x) + nl
        next
        Close()
}

Zip Class Reference

Methods:

Method

Description/Output

SetFileName(cName)

Set the Zip file name

GetFileName()

Return the Zip file name

Open(cMode)

Open File, cMode = “a”, “w” or “r”

Close()

Close the Zip File

AddFile(cFileName)

Add file to the Zip file

ExtractAllFiles(cFolder)

Extract all files from the Zip file

FilesCount()

Return files count in the Zip file

GetFileNameByIndex(nIndex)

Return file name in the Zip file by file index

NewEntry()

Create new ZipEntry object

ZipEntry Class Reference

Methods:

Method

Description/Output

Open(cFileName)

Open new Entry

WriteFile(cFileName)

Write File to the Entry

WriteString(cString)

Write String to the Entry

Close()

Close the Entry