Kore 3
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 <kore3/global.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  kore_file_reader

Macros

#define KORE_DEBUGDIR   "deployment"

Typedefs

typedef enum kore_file_type kore_file_type
typedef struct kore_file_reader kore_file_reader

Enumerations

enum  kore_file_type { KORE_FILE_TYPE_ASSET , KORE_FILE_TYPE_SAVE }

Functions

KORE_FUNC bool kore_file_reader_open (kore_file_reader *reader, const char *filepath, kore_file_type type)
 Opens a file for reading.
KORE_FUNC bool kore_file_reader_from_memory (kore_file_reader *reader, void *data, size_t size)
 Opens a memory area for reading using the file reader API.
KORE_FUNC void kore_file_reader_set_callback (bool(*callback)(kore_file_reader *reader, const char *filename, kore_file_type type))
 Registers a file reader callback.
KORE_FUNC bool kore_file_reader_close (kore_file_reader *reader)
 Closes a file.
KORE_FUNC size_t kore_file_reader_read (kore_file_reader *reader, void *data, size_t size)
 Reads data from a file starting from the current reading-position and increases the reading-position accordingly.
KORE_FUNC size_t kore_file_reader_size (kore_file_reader *reader)
 Figures out the size of a file.
KORE_FUNC size_t kore_file_reader_pos (kore_file_reader *reader)
 Figures out the current reading-position in the file.
KORE_FUNC bool kore_file_reader_seek (kore_file_reader *reader, size_t pos)
 Sets the reading-position manually.
KORE_FUNC float kore_read_f32le (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a little-endian float.
KORE_FUNC float kore_read_f32be (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a big-endian float.
KORE_FUNC uint64_t kore_read_u64le (uint8_t *data)
 Interprets eight bytes starting at the provided pointer as a little-endian uint64.
KORE_FUNC uint64_t kore_read_u64be (uint8_t *data)
 Interprets eight bytes starting at the provided pointer as a big-endian uint64.
KORE_FUNC int64_t kore_read_s64le (uint8_t *data)
 Interprets eight bytes starting at the provided pointer as a little-endian int64.
KORE_FUNC int64_t kore_read_s64be (uint8_t *data)
 Interprets eight bytes starting at the provided pointer as a big-endian int64.
KORE_FUNC uint32_t kore_read_u32le (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a little-endian uint32.
KORE_FUNC uint32_t kore_read_u32be (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a big-endian uint32.
KORE_FUNC int32_t kore_read_s32le (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a little-endian int32.
KORE_FUNC int32_t kore_read_s32be (uint8_t *data)
 Interprets four bytes starting at the provided pointer as a big-endian int32.
KORE_FUNC uint16_t kore_read_u16le (uint8_t *data)
 Interprets two bytes starting at the provided pointer as a little-endian uint16.
KORE_FUNC uint16_t kore_read_u16be (uint8_t *data)
 Interprets two bytes starting at the provided pointer as a big-endian uint16.
KORE_FUNC int16_t kore_read_s16le (uint8_t *data)
 Interprets two bytes starting at the provided pointer as a little-endian int16.
KORE_FUNC int16_t kore_read_s16be (uint8_t *data)
 Interprets two bytes starting at the provided pointer as a big-endian int16.
KORE_FUNC uint8_t kore_read_u8 (uint8_t *data)
 Interprets one byte starting at the provided pointer as a uint8.
KORE_FUNC int8_t kore_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

◆ kore_file_reader_close()

KORE_FUNC bool kore_file_reader_close ( kore_file_reader * reader)

Closes a file.

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

◆ kore_file_reader_from_memory()

KORE_FUNC bool kore_file_reader_from_memory ( kore_file_reader * 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

◆ kore_file_reader_open()

KORE_FUNC bool kore_file_reader_open ( kore_file_reader * reader,
const char * filepath,
kore_file_type type )

Opens a file for reading.

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

◆ kore_file_reader_pos()

KORE_FUNC size_t kore_file_reader_pos ( kore_file_reader * 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

◆ kore_file_reader_read()

KORE_FUNC size_t kore_file_reader_read ( kore_file_reader * 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

◆ kore_file_reader_seek()

KORE_FUNC bool kore_file_reader_seek ( kore_file_reader * 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

◆ kore_file_reader_set_callback()

KORE_FUNC void kore_file_reader_set_callback ( bool(* callback )(kore_file_reader *reader, const char *filename, kore_file_type type))

Registers a file reader callback.

Parameters
callbackThe function to call when opening a file

◆ kore_file_reader_size()

KORE_FUNC size_t kore_file_reader_size ( kore_file_reader * reader)

Figures out the size of a file.

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