Skip to content

infinity.zip

Provides ZIP compression and extraction functionality for archives in files and streams.

Module: infinity.zip

Classes:
Namespaces:
Interfaces:

Example:

infinity.loadModule('infinity.zip');
infinity.loadModule('infinity.fileSystem');

infinity.file.writeString('test.txt', '123');
infinity.file.writeString('test2.txt', '321');

let myArchive = new infinity.zip.file();
myArchive.open('archive.zip', infinity.zip.file.mode.write);

myArchive.add('test.txt');
myArchive.add('test2.txt', 'test3.txt');

myArchive.close();
myArchive.open('archive.zip', infinity.zip.file.mode.read);

myArchive.extract('test3.txt', './');
console.debug(infinity.file.readString('test3.txt'));
//321

myArchive.free();

Classes

file

The class for compression and extraction operations on files in INFINITY.JS.


Properties


comment

Gets or sets comments for the ZIP-archive.

Type: string


fileCount (readonly)

Gets the quantity of files contained inside the ZIP-archive.

Type: number


fileNames (readonly)

Gets the list of files inside the ZIP-archive.

Type: infinity.zip.file.stringArray


Methods


constructor()

Lets you instantiate an INFINITY.JS ZIP-file object instance for operations on files. Doesn't accept parameters.

Signature:

constructor()

Example:

infinity.loadModule('infinity.zip');
let myArchive = new infinity.zip.file();

add()

Adds a file to the ZIP-archive.

Signature:

add( fileName: string, archiveFileName?: string ): void

Parameters:

  • fileName: string

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file to be opened.

  • archiveFileName: string, optional

    The name of the file inside the archive. Can differ from the original file name.

Example:

myArchive.add('dataToCompress.txt');

close()

Closes the ZIP-archive.

Signature:

close(): void

Example:

myArchive.close();

extract()

Extracts the file indicated by the given index number out of the ZIP-archive and writes it to the specified location.

Signature:

extract( index: number, path?: string, createSubDirs?: boolean ): void

Parameters:

  • index: number

    The zero-based index of the file contained in the archive.

  • path: string, optional

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which should contain the decompressed output.

  • createSubDirs: boolean, optional

    Indicates, whether to create subdirectories according to the directory structure inside the ZIP-archive.

Example:

myArchive.extract(3, './', true);

extract()

Extracts the file indicated by the given filename out of the ZIP-archive and writes it to the specified location.

Signature:

extract( fileName: string, path?: string, createSubDirs?: boolean ): void

Parameters:

  • fileName: string

    The name of the file contained in the archive.

  • path: string, optional

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which should contain the decompressed output.

  • createSubDirs: boolean, optional

    Indicates, whether to create subdirectories according to the directory structure inside the ZIP-archive.

Example:

myArchive.extract('toBeExtracted.txt', './', true);

free()

Frees up memory occupied by the INFINITY.JS ZIP-file object instance.

Signature:

free(): void

Example:

myArchive.free();

open()

Opens or creates a ZIP-archive inside an INFINITY.JS ZIP-file object instance.

Signature:

open( fileName: string, mode: infinity.zip.file.mode ): void

Parameters:

  • fileName: string

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to zip-archive.

  • mode: infinity.zip.file.mode

    Specifies the type of access to the zip-archive according to infinity.zip.file.mode. For archive creation the write-access is required.

Example:

infinity.loadModule('infinity.zip');
let myArchive = new infinity.zip.file();
myArchive.open('archive.zip', infinity.zip.file.readWrite);

stream

The class for compression and extraction operations on streams.

Example:

infinity.loadModule('infinity.zip');
let myStream = new infinity.zip.stream();

Properties


comment

Type: string

Gets or sets the comment for the ZIP-archive.


position

Type: number

Gets or sets the pointer position


size

Type: number

Gets or sets the stream size.


fileCount (readonly)

Type: number

Gets the quantity of files contained inside the ZIP-archive.


fileList (readonly)

Type: infinity.zip.stream.fileArray

Gets the list of files inside the ZIP-archive.


Methods


constructor()

Lets you instantiate an INFINITY.JS ZIP-file object instance for operations on streams. Doesn't accept parameters.

Signature:

constructor()

Example:

infinity.loadModule('infinity.zip');
let myStream = new infinity.zip.stream();

add()

Adds a file to the ZIP-archive.

Signature:

add( localFileName: string, archiveFileName?: string, created?: number, modified?: number, lastAccess?: number, comment?: string ): void

Parameters:

  • localFileName: string

    Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file to be opened.

  • archiveFileName: string, optional

    The name of the file inside the archive.

  • created: number, optional

    Sets the file creation timestamp.

  • modified: number, optional

    Sets the timestamp of the last file modification.

  • lastAccess: number, optional

    Sets the timestamp of the last access to the file.

  • comment: string, optional

    Can contain a comment about the file inside the ZIP-archive.

Example:

myStream.add('dataToCompress.txt');

copyFrom()

Copies all or the specified amount of files from the given INFINITY.JS ZIP stream object to the current INFINITY.JS ZIP stream object.

Signature:

copyFrom( stream: infinity.zip.stream, count?: number ): number

Parameters:

  • stream: infinity.zip.stream

    INFINITY.JS ZIP stream object to copy from.

  • count: number, optional

    The number of files to copy.

Return type: number

Example:

myStream.copyFrom(stream);

free()

Frees up memory occupied by the INFINITY.JS ZIP stream object instance.

Signature:

free(): void

Example:

myStream.free();

Namespaces

infinity.zip.file

Interfaces:
Enums:

Interfaces

infinity.zip.file.stringArray

Extends: Array<string>

An array of strings.


Enums

infinity.zip.file.mode

The mode enums specify the mode in which a ZIP-archive is being opened.

Values:

  • read: 1

    Specifies read only acces.

  • readWrite: 2

    Specifies read and write access.

  • write: 3

    Specifies write only acces.

Example:

infinity.loadModule('infinity.zip');
let myArchive = new infinity.zip.file();
myArchive.open('archive.zip', infinity.zip.file.mode.write)

infinity.zip.stream


Interfaces

infinity.zip.stream.fileArray

Extends: Array<{localFileName: string, archiveFileName: string, created: number, modified: number, lastAccess: number, comment: string, crc32: number, size: number}>

An array containing information about the files inside the archive as file objects

Properties:

  • localFileName

    Type: string. filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file to be opened.

  • archiveFileName

    Type: string. The name of the file inside the archive.

  • created

    Type: number. The file creation timestamp.

  • modified

    Type: number. The timestamp of the last file modification.

  • lastAccess

    Type: number. The timestamp of the last access to the file.

  • comment

    Type: string. A comment about the file inside the ZIP-archive.

  • crc32

    Type: number. The crc32 hash s for the file.

  • size

    Type: number. The file size.