libtcoddocumentation

11.3. Using the buffer in input mode

Reading from a compressed file

You can read data from a file (compressed or not) into the buffer.
The function returns the number of (uncompressed) bytes read or 0 if an error occured.

int TCODZip::loadFromFile(const char *filename)

int TCOD_zip_load_from_file(TCOD_zip_t zip, const char *filename)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor.
filenameName of the file

Reading a char from the buffer

char TCODZip::getChar()

char TCOD_zip_get_char(TCOD_zip_t zip)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor

Reading an integer from the buffer

int TCODZip::getInt()

int TCOD_zip_get_int(TCOD_zip_t zip)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor.

Reading a floating point value from the buffer

float TCODZip::getFloat()

float TCOD_zip_get_float(TCOD_zip_t zip)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor.

Reading a string from the buffer

The address returned is in the buffer. It is valid as long as you don't destroy the buffer.

const char *TCODZip::getString()

const char *TCOD_zip_get_string(TCOD_zip_t zip)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor.

Reading a color from the buffer

TCODColor TCODZip::getColor()

TCOD_color_t TCOD_zip_get_color(TCOD_zip_t zip)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor.

Reading a color from the buffer

TCODImage *TCODZip::getImage()

TCOD_image_t TCOD_zip_get_image(TCOD_zip_t zip)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor.

Reading a console from the buffer

TCODConsole *TCODZip::getConsole()

TCOD_console_t TCOD_zip_get_console(TCOD_zip_t zip)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor.

Reading some custom data from the buffer

Note that the getData length must match the length of the data when the file was created (with putData).
The function returns the number of bytes that were stored in the file by the putData call. If more than nbBytes were stored, the function read only nbBytes and skip the rest of them.

int TCODZip::getData(int nbBytes, void *data)

int TCOD_zip_get_data(TCOD_zip_t zip, int nbBytes, void *data)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor.
nbBytesNumber of bytes to read
dataAddress of a pre-allocated buffer (at least nbBytes bytes)
Example:

TCODZip zip;
zip.loadFromFile("myCompressedFile.gz");
char
c=zip.getChar();
int
i=zip.getInt();
float
f= zip.getFloat();
const
char *s=zip.getString();
zip.getData(nbBytes, dataPtr);

TCOD_zip_t zip=TCOD_zip_new();
TCOD_zip_load_from_file(zip,"myCompressedFile.gz");
char
c=TCOD_zip_get_char(zip);
int
i=TCOD_zip_get_int(zip);
float
f=TCOD_zip_get_float(zip);
const
char *s=TCOD_zip_get_string(zip);
TCOD_zip_get_data(zip,nbBytes, dataPtr);


Getting the number of remaining bytes in the buffer

uint32 TCODZip::getRemainingBytes() const

uint32 TCOD_zip_get_remaining_bytes(TCOD_zip_t zip)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor.

Skiping some bytes in the buffer

void TCODZip::skipBytes(uint32 nbBytes)

void TCOD_zip_skip_bytes(TCOD_zip_t zip, uint32 nbBytes)

ParameterDescription
zipIn the C version, the buffer handler, returned by the constructor.
nbBytesnumber of uncompressed bytes to skip