-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
333 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
DPTLib > io > stream | ||
==================== | ||
"stream" is a sub-library of DPTLib for creating data sources and transforms. | ||
|
||
The core type `stream_t` is an interface which can be used to wrap, or create, sources of bytes. The interface is primarily byte oriented but block operations are supported too. Byte access is efficiently implemented as a macro. | ||
|
||
If a stream implementor also accepts a stream as input you can chain together the streams to build pipelines, similar to Unix pipes. | ||
|
||
Implementations of TIFF-style PackBits RLE and "Move to Front" compression and decompression are provided but they're really only intended as examples. | ||
|
||
This is a reimplementation of a technique that I was introduced to by Robin Watts and Paul Gardiner. | ||
|
||
Creating a stream | ||
----------------- | ||
See `stream_mem_create()` and its associated functions for a concrete example of how to construct a stream. | ||
|
||
Using a stream | ||
-------------- | ||
Fetch a **byte** by using `stream_getc(stream)`. If the returned value is EOF then the stream has ended. | ||
|
||
Fetch a **block** by first using `stream_remaining_and_fill(stream)`. This will attempt to fill the buffer `stream->buf` up. Note that we don't specify by how much the buffer will be filled to allow for flexibility. | ||
|
||
Chaining streams | ||
---------------- | ||
You can link streams together to create data pipelines that transform data in sequence. The second stream needs to be written to accept a stream as input, e.g. the example `stream_mtfcomp_create()` works like this. | ||
|
||
Provided example streams | ||
------------------------ | ||
* `stream-stdio` | ||
- Creates a stream from a stdio FILE (read only). | ||
* `stream-mem` | ||
- Creates a stream from a single block of memory (read only). | ||
* `stream-packbits` | ||
- Performs PackBits RLE (de)compression. | ||
* `stream-mtfcomp` | ||
- Provides "move to front" adaptive (de)compression. | ||
|
||
Taking it further | ||
----------------- | ||
Streams can be written to "fork" data into two separate pipes, to "cat" two pipes together, to "zip" pipes, etc. | ||
|
||
Remember to never cross the streams. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.