https://github.com/redthing1/streamz
https://github.com/redthing1/streamz
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/redthing1/streamz
- Owner: redthing1
- Created: 2022-08-12T22:05:56.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-12T22:22:04.000Z (almost 4 years ago)
- Last Synced: 2025-07-03T03:03:05.956Z (12 months ago)
- Language: D
- Size: 50.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# streamz
a stream IO library for D based on freck-streams abandoned source code.
## MemoryStream
Simple in-memory stream.
```D
import std.stdio;
import streamz.face;
import streamz.memorystream;
auto stream = MemoryStream.fromBytes(cast(ubyte[])"Hello", ["Roses": "Are red"]);
stream.seek(0, Seek.end);
stream.write(cast(ubyte[])" World!");
writeln("Roses: ", stream.getMetadata("Roses"));
writeln("Stream content: ", cast(string)stream.getContents);
```
## FileStream
Simple file stream built on top of `std.stdio.File`.
```D
import std.stdio;
import streamz.face;
import streamz.filestream;
auto stream = new FileStream("stream.txt", "w+b", ["Roses": "Are red"]);
stream.write(cast(ubyte[])"Hello World!");
stream.seek(0, Seek.set);
writeln("Roses: ", stream.getMetadata("Roses"));
//.read(1024) Reads 1024 bytes or the whole stream to the end, if it is smaller.
writeln("Stream content: ", cast(string)stream.read(1024));
```
## AppendStream
Reads from multiple streams, one after the other.
```D
import std.stdio;
import streamz.face;
import streamz.memorystream;
import streamz.appendstream;
auto stream1 = MemoryStream.fromBytes(cast(ubyte[])"Hello ");
auto stream2 = MemoryStream.fromBytes(cast(ubyte[])"World");
auto stream3 = MemoryStream.fromBytes(cast(ubyte[])"!");
auto allTogether = new AppendStream([
stream1,
stream2,
stream3,
]);
writeln("Stream content: ", cast(string)allTogether.getContents);
```
## Endianness
Each stream has an endianness attribute with default value `Endian.platform`. This attribute affects on reading/writing scalar types from/to the stream.
```D
import std.stdio;
import streamz.face;
import streamz.memorystream;
import streamz.util: readScalar;
auto stream = MemoryStream.fromBytes(cast(ubyte[])[1, 2, 3, 4]);
stream.setEndian(Endian.little);
stream.seek(0);
auto ret1 = stream.readScalar!uint;
writefln("Returns: %.8x", ret1); //04030201
stream.setEndian(Endian.big);
stream.seek(0);
auto ret2 = stream.readScalar!uint;
writefln("Returns: %.8x", ret2); //01020304
```