Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
StringFile
#1
File I/O like routines for memory loaded files.

The StringFile library can be used for dealing with files that are completely loaded in memory. Since it uses QB64 strings as a backing buffer, no explicit memory management (i.e. freeing) is required. No need to worry about opening, closing, or freeing anything. Everything is nicely cleaned up when it goes out of scope.

API List:
[Image: Screenshot-2023-11-21-234937.png]

I actually have a C version of this, but I made a pure QB64 version for something that I am working on. Sorry, there is no demo for this one. There is some test code in StringFile.bas. Most of it is very simple and straightforward.

Notes:

1. Unlike QB64 file I/O stuff, StringFile is 0 based. Meaning the first byte in the file is at position 0. This helps a lot when porting over code from languages like C.

Stuff like
Code: (Select All)
byte = fgetc(f);
can be replaced by
Code: (Select All)
byte = StringFile_ReadByte(sf)

2. StringFile is optimized for little-endian. So, if you are loading big-endian stuff, ensure you do the necessary byte swaps.

3. Just because the whole file is in memory, you are not allowed to be careless. StringFile will yell at you (read throw errors) if you do stuff like reading past the end of the file or positioning the cursor to a non-existent location.


Attached Files
.bi   StringFile.bi (Size: 672 bytes / Downloads: 86)
.bas   StringFile.bas (Size: 14.11 KB / Downloads: 80)
Reply
#2
Cool. Is this in Toolbox64?
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#3
(12-05-2023, 05:27 AM)grymmjack Wrote: Cool. Is this in Toolbox64?

Yep. It is. I am using this in GIFPlay too.
Reply
#4
(12-05-2023, 09:04 AM)a740g Wrote:
(12-05-2023, 05:27 AM)grymmjack Wrote: Cool. Is this in Toolbox64?

Yep. It is. I am using this in GIFPlay too.

Right, and who wants the "Luxury Version" of this can take The Simplebuffer System (Read Docs) from my Libraries Collection Big Grin
Reply




Users browsing this thread: 1 Guest(s)