11.2. Using the buffer in output mode
- Putting a char in the buffer
- Putting an integer in the buffer
- Putting a floating point value in the buffer
- Putting a string in the buffer
- Putting a color in the buffer
- Putting an image in the buffer
- Putting a console in the buffer
- Putting some custom data in the buffer
- Reading the number of (uncompressed) bytes in the buffer
- Saving the buffer on disk
Putting a char in the buffer
void TCODZip::putChar(char val)
void TCOD_zip_put_char(TCOD_zip_t zip, char val)
Parameter | Description |
---|---|
zip | In the C version, the buffer handler, returned by the constructor. |
val | A 8 bits value to store in the buffer |
Putting an integer in the buffer
void TCODZip::putInt(int val)
void TCOD_zip_put_int(TCOD_zip_t zip, int val)
Parameter | Description |
---|---|
zip | In the C version, the buffer handler, returned by the constructor. |
val | An integer value to store in the buffer |
Putting a floating point value in the buffer
void TCODZip::putFloat(float val)
void TCOD_zip_put_float(TCOD_zip_t zip, float val)
Parameter | Description |
---|---|
zip | In the C version, the buffer handler, returned by the constructor. |
val | A float value to store in the buffer |
Putting a string in the buffer
void TCODZip::putString(const char *val)
void TCOD_zip_put_string(TCOD_zip_t zip, const char *val)
Parameter | Description |
---|---|
zip | In the C version, the buffer handler, returned by the constructor. |
val | A string to store in the buffer |
Putting a color in the buffer
void TCODZip::putColor(const TCODColor *val)
void TCOD_zip_put_color(TCOD_zip_t zip, const TCOD_color_t val)
Parameter | Description |
---|---|
zip | In the C version, the buffer handler, returned by the constructor. |
val | A color to store in the buffer |
Putting an image in the buffer
void TCODZip::putImage(const TCODImage *val)
void TCOD_zip_put_image(TCOD_zip_t zip, const TCOD_image_t val)
Parameter | Description |
---|---|
zip | In the C version, the buffer handler, returned by the constructor. |
val | An image to store in the buffer |
Putting a console in the buffer
void TCODZip::putConsole(const TCODConsole *val)
void TCOD_zip_put_console(TCOD_zip_t zip, const TCOD_console_t val)
Parameter | Description |
---|---|
zip | In the C version, the buffer handler, returned by the constructor. |
val | A console to store in the buffer |
Putting some custom data in the buffer
void TCODZip::putData(int nbBytes, const void *data)
void TCOD_zip_put_data(TCOD_zip_t zip, int nbBytes, const void *data)
Parameter | Description |
---|---|
zip | In the C version, the buffer handler, returned by the constructor. |
nbBytes | Number of bytes to store in the buffer |
val | Address of the data to store in the buffer |
Reading the number of (uncompressed) bytes in the buffer
uint32 TCODZip::getCurrentBytes()
uint32 TCOD_zip_get_current_bytes(TCOD_zip_t zip)
Parameter | Description |
---|---|
zip | In the C version, the buffer handler, returned by the constructor. |
Saving the buffer on disk
Once you have finished adding data in the buffer, you can compress it and save it in a file.
The function returns the number of (uncompressed) bytes saved.
int TCODZip::saveToFile(const char *filename)
int TCOD_zip_save_to_file(TCOD_zip_t zip, const char *filename)
Parameter | Description |
---|---|
zip | In the C version, the buffer handler, returned by the constructor. |
filename | Name of the file |
Example:
TCODZip zip;
zip.putChar('A');
zip.putInt(1764);
zip.putFloat(3.14f);
zip.putString("A string");
zip.putData(nbBytes, dataPtr);
zip.saveToFile("myCompressedFile.gz");
TCOD_zip_t zip=TCOD_zip_new();
TCOD_zip_put_char(zip,'A');
TCOD_zip_put_int(zip,1764);
TCOD_zip_put_float(zip,3.14f);
TCOD_zip_put_string(zip,"A string");
TCOD_zip_put_data(zip,nbBytes, dataPtr);
TCOD_zip_save_to_file(zip,"myCompressedFile.gz");