System.IO Extension
Posted: Thu Sep 04, 2008 12:28 pm
This is a little something I whipped up, since I've never been satisfied with existing forms of reading/writing data to a file...
The main class in this library is the DataStream which is a wrapper which combines the binary reader and binary writer with a few extra features:
The Flags class is an abstact class with 4 ready made inherited classes (8,16,32,64 bits). To see how to expand on these look at the source. The Flags class uses a compact algorithm which I came up with to read/write bits, people who hate messy code should like it
Bare in mind I haven't tested any of this, so if you find any bugs let me know (its possible the flags write in reverse for halo standards but its easy to fix if this is the case)
Source Code Here
The main class in this library is the DataStream which is a wrapper which combines the binary reader and binary writer with a few extra features:
- Bookmark Stack -
- IMO this is one of the best ideas I've ever come up with, its also very simple. If you are at a point in a file but you want to go to another part of the file and then return (eg for a reflexive), simply ".PushBookmark" to add a return point and ".PopBookmark" to return. An understanding of the stack structure is good to understand how useful this is.
- When reading or writing a string you can specify how to do so. There are 3 options, Characters Only (When reading this requires the user to specify the character count), Null Terminated and System IO Standard.
Reverse bool: If true the string is automatically reversed after read / before write.
- Just a simple wrapper that returns a MemoryStream instead of a byte array.
IDatatizable Read/Write - Ability to read/write any user defined class/struct via the included IDatatizable interface.
Extendible Design - The Binary Reader and Binary Writer are exposed to inherited class to allow you to easily add your own read/write functions.
The Flags class is an abstact class with 4 ready made inherited classes (8,16,32,64 bits). To see how to expand on these look at the source. The Flags class uses a compact algorithm which I came up with to read/write bits, people who hate messy code should like it
Bare in mind I haven't tested any of this, so if you find any bugs let me know (its possible the flags write in reverse for halo standards but its easy to fix if this is the case)
Source Code Here