-
Notifications
You must be signed in to change notification settings - Fork 13
Using Binary Files
To open a binary file, simply declare a fplFileHandle somewhere and call fplFileOpenBinary() with a valid UTF-8 path to open it.
fileHandle;
if (("myimage.jpg", &fileHandle)) {
// ... read data
(&fileHandle);
}Note: Call
fplFileClose() to close a file when you are done.
To read a block of n-bytes from the file starting from the current file position, simply call fplFileReadBlock() with your filehandle and a buffer to read into.
struct jpeg_header; // defined somewhere
fileHandle;
if (("myimage.jpg", &fileHandle)) {
size_t read;
// Read the first 4 characters
char fourCC[4];
read = (&fileHandle, 4, fourCC, sizeof(fourCC));
(read == 4);
// or
// Read a JPEG-Header
jpeg_header jpegHeader;
size_t read;
read = (&fileHandle, sizeof(jpegHeader), &jpegHeader, sizeof(jpegHeader));
(read == sizeof(jpegHeader));
(&fileHandle);
}To create a binary file, simply declare a fplFileHandle somewhere and call fplFileCreateBinary() with a valid UTF-8 path to open it.
If the file already exists, it will be overwritten automatically.
fileHandle;
if (("myimage.jpg", &fileHandle)) {
// ... write data
(&fileHandle);
}Note: Call
fplFileClose() to close a file when you are done.
To write n-bytes of memory into an opened file beginning at the current file position, simply call fplFileWriteBlock() with your filehandle and the buffer you want to write.
fileHandle;
char *saveGameFilePath = ...
if ((saveGameFilePath, &fileHandle)) {
char savegameFourCC[4] = {'S', 'A', 'V', 'E'};
uint8_t *savegameDataPtr = ...;
size_t savegameDataSize = ...;
// Write a savegame
(&fileHandle, savegameFourCC, 4);
(&fileHandle, savegameDataPtr, savegameDataSize);
(&fileHandle);
}Call fplFileGetPosition() to get the current file position from an opened fplFileHandle .
fileHandle = ...
size_t curPos = (&fileHandle);Call fplFileSetPosition() to set the current file position on an opened fplFileHandle .
fileHandle = ...
// Seek 4-bytes forwards from the current position
fplFileSetPosition(&fileHandle, 4, );
// Seek 4-bytes backwards from the current position
(&fileHandle, -4, );
// Seek to the 128-byte from the beginning (Absolute seeking)
(&fileHandle, 128, );
// Seek to the start of the file
(&fileHandle, 0, );
// Seek to the end of the file (Get file length)
size_t fileLength = (&fileHandle, 0, );There are three versions for file reading/writing and seeking:
- A version which uses uint32_t or int32_t (32-bit only, Limited to 2 GB of file = 2^31).
- A version which uses uint64_t or int64_t (64-bit only, Limited to 2 TB of file = 2^63).
- A default version which uses size_t or intptr_t always and use either the 32-bit or the 64-bit, depending on the compiled CPU-Architecture. See the next sections for more details.
Uses either 32-bit or the 64-bit, depending on the compiled CPU architecture:
- fplFileSetPosition() maps to fplFileSetPosition32() or fplFileSetPosition64()
- fplFileGetPosition() maps to fplFileGetPosition32() or fplFileGetPosition64()
- fplFileReadBlock() maps to fplFileReadBlock32() or fplFileReadBlock64()
- fplFileWriteBlock() maps to fplFileWriteBlock32() or fplFileWriteBlock64()
- fplFileGetSizeFromPath() maps to fplFileGetSizeFromPath32() or fplFileGetSizeFromPath64()
- fplFileGetSizeFromHandle() maps to fplFileGetSizeFromHandle32() or fplFileGetSizeFromHandle64()
Limited to 32-bit:
- fplFileSetPosition32()
- fplFileGetPosition32()
- fplFileReadBlock32()
- fplFileWriteBlock32()
- fplFileGetSizeFromPath32()
- fplFileGetSizeFromHandle32()
Up to 2-TB (64-bit):
- Assertion & Debug
- Atomic operations
- Audio functions
- Clipboard functions
- Console functions
- Constants
- Display/Monitor functions
- Dynamic library loading
- Error Handling
- Files/IO functions
- Function macros
- Hardware Infos
- Input types and functions
- Localization functions
- Logging
- Memory Macros
- Memory functions
- Operating system Infos
- Path functions
- Platform functions
- Session Infos
- Settings & Configurations
- Storage class identifiers
- String functions
- Threading and synchronizations routines
- Timing functions
- Video functions
- Window events
- Window functions
- fplARMCPUCapabilities
- fplAudioChannelMap
- fplAudioDeviceID
- fplAudioDeviceInfo
- fplAudioFormat
- fplAudioSettings
- fplColor32
- fplConditionVariable
- fplConsoleSettings
- fplCPUCapabilities
- fplCPUIDLeaf
- fplDateTime
- fplDateTimeCreationResult
- fplDateTimeResult
- fplDisplayInfo
- fplDisplayMode
- fplDynamicLibraryHandle
- fplEndianess
- fplEvent
- fplFileEntry
- fplFileHandle
- fplFilePermissions
- fplFileTimeStamps
- fplGamepadButton
- fplGamepadData
- fplGamepadEvent
- fplGamepadInfo
- fplGamepadInputBinding
- fplGamepadMapping
- fplGamepadSettings
- fplGamepadState
- fplGamepadStates
- fplGraphicsApiSettings
- fplImageSource
- fplInputBackendMask
- fplInputBackendSupport
- fplInputDevice
- fplInputDeviceGuid
- fplInputSettings
- fplInternalConditionVariable
- fplInternalDynamicLibraryHandle
- fplInternalFileEntryHandle
- fplInternalFileHandle
- fplInternalFileRootInfo
- fplInternalMutexHandle
- fplInternalSemaphoreHandle
- fplInternalSignalHandle
- fplInternalThreadHandle
- fplKeyboardEvent
- fplKeyboardState
- fplLogSettings
- fplLogWriter
- fplLogWriterConsole
- fplLogWriterCustom
- fplMemoryAllocationSettings
- fplMemoryBlock
- fplMemoryInfos
- fplMemorySettings
- fplMouseEvent
- fplMouseState
- fplMutexHandle
- fplOpenGLSettings
- fplOSVersionInfos
- fplSemaphoreHandle
- fplSettings
- fplSignalHandle
- fplSpecificAudioSettings
- fplThreadHandle
- fplThreadParameters
- fplTimestamp
- fplVersionInfo
- fplVideoBackBuffer
- fplVideoRect
- fplVideoRequirements
- fplVideoRequirementsVulkan
- fplVideoSettings
- fplVideoSurface
- fplVideoSurfaceOpenGL
- fplVideoSurfaceVulkan
- fplVideoWindow
- fplVulkanSettings
- fplWindowCallbacks
- fplWindowDropFiles
- fplWindowEvent
- fplWindowPosition
- fplWindowSettings
- fplWindowSize
- fplX86CPUCapabilities