Page 1 of 1

System.IO Extension Source

Posted: Thu Sep 04, 2008 8:23 pm
by XZodia
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:
  • 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.
    3 Different String Read/Write Methods -
    • 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.
    Memory Stream Read/Write -
    • Just a simple wrapper that returns a MemoryStream instead of a byte array.
    Flags Read/Write - Ability to read/write the included Flags class.
    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 IDatatizable interface adds a Write(DataStream) void to your class/struct where you can write whatever info you like to write your class. To read your class/struct from a DataStream add a constructor with just a DataStream variable and read whatever info you like.

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 :P

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)

Re: System.IO Extension Source

Posted: Fri Sep 05, 2008 1:54 am
by OwnZ joO
The bookmark stack seems like a pretty good idea.