Buffered file access – Bfile
There may already be a method or library for handling files in memory but I wrote this to easily add and remove bytes without constantly reading or writing to a file. Bfile reads the whole file into memory before working on it by using the bfread, bfwrite, bfclip and bfinsert functions.
bfopen() opens a file and sets the initial values in the Bfile struct.
bfclose() flushes the buffer to the file and closes the file.
bfflush() flushes the buffer to the file.
bfread() reads the entire file into a Bfile buffer.
bfwrite() writes from memory to the Bfile buffer, but not to the file.
bfclip() removes data from the Bfile and adjusts the file size.
bfinsert() inserts data from memory into the Bfile and adjusts the file size.
Writing to the file needs to end with a bfflush and this is done automatically when the file is closed with bfclose.