Skip to content

infinity.iniFile

Provides functionality for reading and writing structured .ini files.

Attention: .ini files must use the ANSI (windows1252) charset in order to be read and written by these functions.

Module: infinity.iniFile

Classes:
Interfaces:

Example:

infinity.loadModule('infinity.iniFile');

let myIniFile = new infinity.iniFile('../test.ini');
try
{
myIniFile.writeFloat('testSection', 'testSetting', 1.1);
myIniFile.writeBoolean('testSection', 'testConfig', true);
myIniFile.writeString('plusSection', 'plusSetting', 'c:/tmp/');


if(myIniFile.sectionExists('testSection')){

    console.debug(myIniFile.readSection('testSection'));
    //["testSetting","testConfig"]

    console.debug(myIniFile.readSectionValues('testSection'));
    //[{"name":"testSetting","value":"1.1"},{"name":"testConfig","value":"1"}]

    console.debug(myIniFile.readFloat('testSection', 'testSetting', 2.2));
    //1.1

    console.debug(myIniFile.readBoolean('testSection', 'testSetting', false ));
    //false

    console.debug(myIniFile.readInteger('testSection', 'testConfig', 2));
    //1

    console.debug(myIniFile.readString('plusSection', 'plusSetting', 'D:/'));
    //c:/tmp/

    myIniFile.eraseSection('testSection');
} 

console.debug(myIniFile.readSections());
//["plusSection"]

} finally {
  myIniFile.free();
}

Classes

iniFile

The class for operations with ini files.

Example:

infinity.loadModule('infinity.iniFile');
let myIniFile = new infinity.iniFile(fileName);

Methods


constructor()

Lets you create an INFINITY.JS ini-file object instance.

Signature:

constructor( fileName: string, encoding?: infinity.encoding )

Parameters:

  • fileName: string

    The name of the ini-file.

  • encoding: infinity.encoding, optional

    The encoding of the file contents.

Example:

infinity.loadModule('infinity.iniFile');
let myIniFile = new infinity.iniFile('../test.ini');

deleteKey()

Deletes an entry with its value from the opened ini-file.

Signature:

deleteKey( section: string, ident: string ): void

Parameters:

  • section: string

    The ini-file section to delete an entry from.

  • ident: string

    The key of the entry to be deleted.

Example:

myIniFile.deleteKey('testSection', 'testSetting');

eraseSection()

Erases a whole section from the opened ini-file.

Signature:

eraseSection( section: string ): void

Parameters:

  • section: string

    The section to be erased.

Example:

myIniFile.eraseSection('testSection');

free()

Frees up memory occupied by the ini-file object instance.

Signature:

free(): void

Example:

myIniFile.free();

readBoolean()

Reads a value out of the specified section and key from the opened ini-file and, if possible, returns it as a boolean, otherwise the default value is returned.

Signature:

readBoolean( section: string, ident: string, defaultValue: boolean ): boolean

Parameters:

  • section: string

    The section to read from.

  • ident: string

    The key to be read from.

  • defaultValue: boolean

    The default value to return in case of the read value being blank or of another type.

Return type: boolean

Example:

myIniFile.readBoolean('testSection', 'testSetting', true );

readFloat()

Reads a value out of the specified section and key from the opened ini-file and, if possible, returns it as a float number, otherwise the default value is returned.

Signature:

readFloat( section: string, ident: string, defaultValue: number ): number

Parameters:

  • section: string

    The section to read from.

  • ident: string

    The key to be read from.

  • defaultValue: number

    The default value to return in case of the read value being blank or of another type.

Return type: number

Example:

myIniFile.readFloat('testSection', 'testSetting', 1.1);

readInteger()

Reads a value (up to 32 bits) out of the specified section and key from the opened ini-file and, if possible, returns it as an integer number, otherwise the default value is returned.

Signature:

readInteger( section: string, ident: string, defaultValue: number ): number

Parameters:

  • section: string

    The section to read from.

  • ident: string

    The key to be read from.

  • defaultValue: number

    The default value to return in case of the read value being blank or of another type.

Return type: number

Example:

myIniFile.readInteger('testSection', 'testSetting', 3);

readInt64()

Reads a value (up to 64 bits) out of the specified section and key from the opened ini-file and, if possible, returns it as an integer number, otherwise the default value is returned.

Signature:

readInt64( section: string, ident: string, defaultValue: number ): number

Parameters:

  • section: string

    The section to read from.

  • ident: string

    The key to be read from.

  • defaultValue: number

    The default value to return in case of the read value being blank or of another type.

Return type: number

Example:

myIniFile.readInt64('testSection', 'testSetting', 5147483647);

readSection()

Returns an array with the names of the setting keys of the specified section.

Signature:

readSection( section: string ): infinity.iniFile.stringArray

Parameters:

  • section: string

    The section to read from.

Return type: infinity.iniFile.stringArray

Example:

myIniFile.readSection('testSection');

readSectionValues()

Returns an array with the section's key names and values.

Signature:

readSectionValues( section: string ): infinity.iniFile.valueArray

Parameters:

  • section: string

    The section to read from.

Return type: infinity.iniFile.valueArray

Example:

myIniFile.readSectionValues('testSection');

readSections()

Returns an array of the sections present in the opened ini-file.

Signature:

readSections(): infinity.iniFile.stringArray

Return type: infinity.iniFile.stringArray

Example:

myIniFile.readSections();

readString()

Reads a value out of the opened ini-file and returns it as a string.

Signature:

readString( section: string, ident: string, defaultValue: string ): string

Parameters:

  • section: string

    The section to read from.

  • ident: string

    The key to be read from.

  • defaultValue: string

    The default value to return in case of the read value being blank or of another type.

Return type: string

Example:

myIniFile.readString('testSection', 'testSetting', 'c:/tmp/');

sectionExists()

Specifies whether the given section exists inside the opened ini-file.

Signature:

sectionExists( section: string ): boolean

Parameters:

  • section: string

    The section to check for.

Return type: boolean

Example:

if(myIniFile.sectionExists('testSection')){
  //...
}

updateFile()

Flushes the actual state of the file to storage.

Signature:

updateFile(): void

Example:

myIniFile.updateFile();

valueExists()

Specifies whether the given value exists at the specified key and section inside the opened ini-file in the.

Signature:

valueExists( section: string, ident: string ): boolean

Parameters:

  • section: string

    The section to check in.

  • ident: string

    The key to be read from.

Return type: boolean

Example:

myIniFile.valueExists('testSection', 'testSetting');

writeBoolean()

Writes the given boolean value to the specified key and section of the opened ini-file.

Signature:

writeBoolean( section: string, ident: string, value: boolean ): void

Parameters:

  • section: string

    The section to write to.

  • ident: string

    The key to write to.

  • value: boolean

    The value to write.

Example:

myIniFile.writeBoolean('testSection', 'testConfig', true);

writeFloat()

Writes the given float value to the specified key and section of the opened ini-file.

Signature:

writeFloat( section: string, ident: string, value: number ): void

Parameters:

  • section: string

    The section to write to.

  • ident: string

    The key to write to.

  • value: number

    The value to write.

Example:

myIniFile.writeFloat('testSection', 'testSetting', 1.1);

writeInteger()

Writes the given integer value (up to 32 bits) to the specified key and section of the opened ini-file.

Signature:

writeInteger( section: string, ident: string, value: number ): void

Parameters:

  • section: string

    The section to write to.

  • ident: string

    The key to write to.

  • value: number

    The value to write.

Example:

myIniFile.writeInteger('testSection', 'testSetting', 3);

writeInt64()

Writes the given integer value (up to 64 bits) to the specified key and section of the opened ini-file.

Signature:

writeInt64( section: string, ident: string, value: number ): void

Parameters:

  • section: string

    The section to write to.

  • ident: string

    The key to write to.

  • value: number

    The value to write.

Example:

myIniFile.writeInt64('testSection', 'testSetting', 5147483647);

writeString()

Writes the given string value to the specified key and section of the opened ini-file.

Signature:

writeString( section: string, ident: string, value: string ): void

Parameters:

  • section: string

    The section to write to.

  • ident: string

    The key to write to.

  • value: string

    The value to write.

Example:

myIniFile.writeString('plusSection', 'plusSetting', 'c:/tmp/');

Interfaces

stringArray

Extends: Array<string>

An array of strings.


valueArray

Extends: Array<{name: string, value: string}>

An array of keys and values.