This module implements a zip archive creator/reader/modifier.
TZipArchive = object of TObject
mode: TFileMode
w: PZip
-
represents a zip archive
PZipFileStream = ref TZipFileStream
-
a reader stream of a file within a zip archive
proc open(z: var TZipArchive; filename: string; mode: TFileMode = fmRead): bool {.
raises: [EOS], tags: [FReadDir, FWriteDir].}
-
Opens a zip file for reading, writing or appending. All file modes are supported. Returns true iff successful, false otherwise.
proc close(z: var TZipArchive) {.raises: [], tags: [].}
-
Closes a zip file.
proc createDir(z: var TZipArchive; dir: string) {.raises: [], tags: [].}
-
Creates a directory within the z archive. This does not fail if the directory already exists. Note that for adding a file like "path1/path2/filename" it is not necessary to create the "path/path2" subdirectories - it will be done automatically by addFile.
proc addFile(z: var TZipArchive; dest, src: string) {.raises: [EIO], tags: [].}
-
Adds the file src to the archive z with the name dest. dest may contain a path that will be created.
proc addFile(z: var TZipArchive; file: string) {.raises: [EIO], tags: [].}
-
A shortcut for addFile(z, file, file), i.e. the name of the source is the name of the destination.
proc addFile(z: var TZipArchive; dest: string; src: PStream) {.
raises: [E_Base, EIO], tags: [FReadIO, FTime].}
-
Adds a file named with dest to the archive z. dest may contain a path. The file's content is read from the src stream.
proc getStream(z: var TZipArchive; filename: string): PZipFileStream {.
raises: [], tags: [].}
-
returns a stream that can be used to read the file named filename from the archive z. Returns nil in case of an error. The returned stream does not support the setPosition, getPosition, writeData or atEnd methods.
proc extractFile(z: var TZipArchive; srcFile: string; dest: PStream) {.
raises: [E_Base], tags: [FWriteIO, FReadIO].}
-
extracts a file from the zip archive z to the destination stream.
proc extractFile(z: var TZipArchive; srcFile: string; dest: string) {.
raises: [EOutOfMemory, E_Base], tags: [FWriteIO, FReadIO].}
-
extracts a file from the zip archive z to the destination filename.
proc extractAll(z: var TZipArchive; dest: string) {.
raises: [EOutOfMemory, E_Base], tags: [FWriteIO, FReadIO].}
-
extracts all files from archive z to the destination directory.
iterator walkFiles(z: var TZipArchive): string {.raises: [], tags: [].}
-
walks over all files in the archive z and returns the filename (including the path).