Kore
Loading...
Searching...
No Matches
filereader.h File Reference

Provides an API very similar to fread and friends but handles the intricacies of where files are actually hidden on each supported system. More...

#include <kinc/global.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  kinc_file_reader

Macros

#define KINC_DEBUGDIR   "Deployment"
#define KINC_FILE_TYPE_ASSET   0
#define KINC_FILE_TYPE_SAVE   1

Typedefs

typedef struct kinc_file_reader kinc_file_reader_t

Functions

KINC_FUNC bool kinc_file_reader_open (kinc_file_reader_t *reader, const char *filepath, int type)
 Opens a file for reading.
KINC_FUNC bool kinc_file_reader_from_memory (kinc_file_reader_t *reader, void *data, size_t size)
 Opens a memory area for reading using the file reader API.
KINC_FUNC void kinc_file_reader_set_callback (bool(*callback)(kinc_file_reader_t *reader, const char *filename, int type))
 Registers a file reader callback.
KINC_FUNC bool kinc_file_reader_close (kinc_file_reader_t *reader)
 Closes a file.
KINC_FUNC size_t kinc_file_reader_read (kinc_file_reader_t *reader, void *data, size_t size)
 Reads data from a file starting from the current reading-position and increases the reading-position accordingly.
KINC_FUNC size_t kinc_file_reader_size (kinc_file_reader_t *reader)
 Figures out the size of a file.
KINC_FUNC size_t kinc_file_reader_pos (kinc_file_reader_t *reader)
 Figures out the current reading-position in the file.
KINC_FUNC bool kinc_file_reader_seek (kinc_file_reader_t *reader, size_t pos)
 Sets the reading-position manually.
KINC_FUNC float kinc_read_f32le (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a little-endian float.
KINC_FUNC float kinc_read_f32be (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a big-endian float.
KINC_FUNC uint64_t kinc_read_u64le (uint8_t *data)
 Interprets eight bytes starting at the provided pointer as a little-endian uint64.
KINC_FUNC uint64_t kinc_read_u64be (uint8_t *data)
 Interprets eight bytes starting at the provided pointer as a big-endian uint64.
KINC_FUNC int64_t kinc_read_s64le (uint8_t *data)
 Interprets eight bytes starting at the provided pointer as a little-endian int64.
KINC_FUNC int64_t kinc_read_s64be (uint8_t *data)
 Interprets eight bytes starting at the provided pointer as a big-endian int64.
KINC_FUNC uint32_t kinc_read_u32le (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a little-endian uint32.
KINC_FUNC uint32_t kinc_read_u32be (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a big-endian uint32.
KINC_FUNC int32_t kinc_read_s32le (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a little-endian int32.
KINC_FUNC int32_t kinc_read_s32be (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a big-endian int32.
KINC_FUNC uint16_t kinc_read_u16le (uint8_t *data)
 Interprets two bytes starting at the provided pointer as a little-endian uint16.
KINC_FUNC uint16_t kinc_read_u16be (uint8_t *data)
 Interprets two bytes starting at the provided pointer as a big-endian uint16.
KINC_FUNC int16_t kinc_read_s16le (uint8_t *data)
 Interprets two bytes starting at the provided pointer as a little-endian int16.
KINC_FUNC int16_t kinc_read_s16be (uint8_t *data)
 Interprets two bytes starting at the provided pointer as a big-endian int16.
KINC_FUNC uint8_t kinc_read_u8 (uint8_t *data)
 Interprets one byte starting at the provided pointer as a uint8.
KINC_FUNC int8_t kinc_read_s8 (uint8_t *data)
 Interprets one byte starting at the provided pointer as an int8.

Detailed Description

Provides an API very similar to fread and friends but handles the intricacies of where files are actually hidden on each supported system.

Function Documentation

◆ kinc_file_reader_close()

KINC_FUNC bool kinc_file_reader_close ( kinc_file_reader_t * reader)

Closes a file.

Parameters
readerThe file to close
Returns
Whether the file could be closed

◆ kinc_file_reader_from_memory()

KINC_FUNC bool kinc_file_reader_from_memory ( kinc_file_reader_t * reader,
void * data,
size_t size )

Opens a memory area for reading using the file reader API.

Parameters
readerThe reader to initialize for reading
dataA pointer to the memory area to read
sizeThe size of the memory area
Returns
This function always returns true

◆ kinc_file_reader_open()

KINC_FUNC bool kinc_file_reader_open ( kinc_file_reader_t * reader,
const char * filepath,
int type )

Opens a file for reading.

Parameters
readerThe reader to initialize for reading
filepathA filepath to identify a file
typeLooks for a regular file (KINC_FILE_TYPE_ASSET) or a save-file (KINC_FILE_TYPE_SAVE)
Returns
Whether the file could be opened

◆ kinc_file_reader_pos()

KINC_FUNC size_t kinc_file_reader_pos ( kinc_file_reader_t * reader)

Figures out the current reading-position in the file.

Parameters
readerThe reader which's reading-position to figure out
Returns
The current reading-position

◆ kinc_file_reader_read()

KINC_FUNC size_t kinc_file_reader_read ( kinc_file_reader_t * reader,
void * data,
size_t size )

Reads data from a file starting from the current reading-position and increases the reading-position accordingly.

Parameters
readerThe reader to read from
dataA pointer to write the data to
sizeThe amount of data to read in bytes
Returns
The number of bytes that were read - can be less than size if there is not enough data in the file

◆ kinc_file_reader_seek()

KINC_FUNC bool kinc_file_reader_seek ( kinc_file_reader_t * reader,
size_t pos )

Sets the reading-position manually.

Parameters
readerThe reader which's reading-position to set
posThe reading-position to set
Returns
Whether the reading position could be set

◆ kinc_file_reader_set_callback()

KINC_FUNC void kinc_file_reader_set_callback ( bool(* callback )(kinc_file_reader_t *reader, const char *filename, int type))

Registers a file reader callback.

Parameters
callbackThe function to call when opening a file

◆ kinc_file_reader_size()

KINC_FUNC size_t kinc_file_reader_size ( kinc_file_reader_t * reader)

Figures out the size of a file.

Parameters
readerThe reader which's file-size to figure out
Returns
The size in bytes