The BetterStreams library is a collection of three classes that aid in manipulating streams. AsyncStream and BetterBufferedStream wrap existing streams to improve I/O performance. AsyncStream provides simple, fast asynchronous I/O via the standard Read() and Write() methods without the overhead and complexity of BeginRead/EndRead and BeginWrite/EndWrite, while BetterBufferedStream is similar to System.IO.BufferedStream but with much more efficient seeks and "peeks". Finally, the static AlternateStreams class adds the ability to manipulate NTFS alternate data streams (ADS) which are a great way to add metadata to a file or create compound storage (multiple data streams in a single file). The 100% managed code library requires the .Net Framework 2.0 (or later) and is both 32- (x86) and 64- (x64) bit compatible.
To try BetterStreams in your own applications, please visit the download page for a free, thirty day evaluation copy.
The AsyncStream class wraps an existing stream and provides asynchronous I/O via the standard Read(), ReadByte(), Write(), and WriteByte() methods; if called on the wrapped stream directly these would require waiting for I/O to the underlying device (such as a disk) but the AsyncStream asynchronously and automatically fills or flushes its internal buffer from or to the wrapped stream using a background thread and will never block so long as sufficient bytes are available in the buffer. Even if your application logic is already built around synchronous I/O, simply replacing the original stream with an AsyncStream can increase performance, sometimes dramatically, with as little as a single-line change to your code [example]. It can also improve performance when passed to methods that manipulate streams, such as HashAlgorithm.ComputeHash() [example]. AsyncStreams provide elegant exception handling, properties for fine-tuning performance and behavior when desired, and, like BetterBufferedStreams, efficient in-buffer seeks.
AlternateStreams enables you to read, write, delete, create and list alternate data streams (ADS) in an NTFS file. Under NTFS, each file has a "main" unnamed stream (this is the one the Framework's file I/O classes manipulate) as well as zero or more "alternate" named streams; for example, Internet Explorer uses an alternate stream named "Zone.Identifier" to record which security zone a downloaded file came from, and in general they can be used to conveniently store arbitrary metadata for a file without the need to resort to a database or a separate metadata file. They can also be used to create "compound storage" for application data: if your application needs to serialize ten objects to a single file, you would normally sequentially write them in XML or binary; however, to modify any of the objects, the entire file must be rewritten. With alternate streams you can simply create a separate named stream for each object and modify these individually. Please note that AlternateStreams requires Windows 2000/XP or later. [examples: 1, 2]
BetterBufferedStream is similar to the Framework's System.IO.BufferedStream but improves seeking while reading a stream. BufferedStreams (and FileStreams) are extremely inefficient when repositioning within buffered data--instead of simply moving forward or backward within the buffer as BetterBufferedStream does, they will instead seek on the underlying the stream and then completely refill the buffer, yielding very poor performance. BetterBufferedStream can also optionally "read behind" a specified number of bytes to ensure efficient peeking. [example]
Jeff Pasternack received his bachelor's degree in computer science from the University of California, Berkeley in 2004 and is currently a graduate student at the University of Illinois at Urbana-Champaign.
-
For questions, suggestions or comments about the BetterStreams library, please email me at jeff@betterstreams.com .
For academic correspondence, please email me at jpaster2 (atsign) uiuc.edu .