User Tools

Site Tools


DzGZFile

DAZ Script *.gz (gzip) file I/O class.

More...

Inherits :

Enumerations

Constructors

DAZ Script
DzGZFile ( String file )

Methods

DAZ Script
voidclose ()
Booleaneof ()
Booleanopen ( AccessMode accessMode )
Stringread ()
NumberreadByte ()
ByteArrayreadByteLine ()
StringreadLine ()
ArrayreadLines ()
Booleanunzip ( String filename )
voidwrite ( String data, Number length=-1 )
voidwriteByte ( Number byte )
voidwriteLine ( String data )
Booleanzip ( String filename )

Detailed Description

This class provides DAZ Script functionality for reading and writing *.gz ('gzipped') files. A high-level interface for zipping/unzipping files is provided with the functions zip() and unzip(). Also, a low-level interface is provided, allowing scripts to read and write compressed files directly.

Enumerations


: AccessMode

Enumerated values used with open() to describe the mode in which a file is opened.

  • ReadOnly - Open the file for reading only.
  • WriteOnly - Open the file for writing only.
  • ReadWrite - Open the file for reading and writing.
  • Append - The file is opened in append mode, so that all data is written to the end of the file.
  • Truncate - If possible, the file is truncated before it is opened. All earlier contents of the file are lost.
  • Text - When reading, the end-of-line terminators are translated to '

'. When writing, the end-of-line terminators are translated to the local encoding.

  • Translate - Alias for Text.

Constructors


DzGZFile( String file )

Creates a gzip file with the given file name.

Parameter(s):

  • file - The path of the *.gz file.

Methods


void : close()

Closes the file.


Boolean : eof()

Return Value:

  • true if the current file position is at the end of the file, otherwise false.

Boolean : open( AccessMode accessMode )

Open the file with the given mode.

Parameter(s):

  • accessMode - The access mode to open with.

Return Value:

  • true if the file was opened successfully, otherwise false.

String : read()

Reads the entire file.

Return Value:

  • The uncompressed file contents as a string.

Number : readByte()

Read one uncompressed character from the file buffer.

Return Value:

  • The next uncompressed character read from the file.

ByteArray : readByteLine()

Read a line of text from the file.

Return Value:

  • The next file line as a byte array.

Since:

  • 4.16.1.25

String : readLine()

Read an uncompressed line of text from the file.

Return Value:

  • The next uncompressed file line as a string.

Array : readLines()

Uncompresses the entire file and splits it into lines of text.

Return Value:

  • A list of uncompressed text lines from the file.

Boolean : unzip( String filename )

Unzips this file into the given filename.

Parameter(s):

  • filename - The name of the file to write to.

true if the file was successfully unzipped, otherwise false.


void : write( String data, Number length=-1 )

Write a string to the file compression buffer.

Parameter(s):

  • data - The string to write to the file.
  • length - The maximum number of characters to write to the file. If this is less than 1 (default), the whole string is written.

void : writeByte( Number byte )

Write a single byte (character) to the file compression buffer.

Parameter(s):

  • byte - The character to write to the file.

void : writeLine( String data )

Write a line of text to the file compression buffer.

Parameter(s):

  • data - The string to write to the file - a new line character will be written immediately following the string contents.

Boolean : zip( String filename )

Replaces this file's contents with the gzipped contents of the given file. If this file does not exist, it will be created.

Parameter(s):

  • filename - The name of the file to replace this file's contents with.

Return Value:

  • true if the file was successfully zipped, otherwise false.