freck-streams 1.2.0
Easy-to-use I/O streams library
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
Freck Streams
This packae contains primitives for I/O using streams and stream decorators.
MemoryStream
Simple in-memory stream.
import std.stdio;
import freck.streams.streaminterface;
import freck.streams.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
.
import std.stdio;
import freck.streams.streaminterface;
import freck.streams.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.
import std.stdio;
import freck.streams.streaminterface;
import freck.streams.memorystream;
import freck.streams.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.
import std.stdio;
import freck.streams.streaminterface;
import freck.streams.memorystream;
import freck.streams.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
- Registered by Maxim Freck
- 1.2.0 released 6 years ago
- maxfreck/freck-streams
- BOOST-1.0
- Authors:
- Dependencies:
- none
- Versions:
-
1.2.0 2018-Mar-12 1.1.0 2018-Mar-11 1.0.1 2018-Mar-11 1.0.0 2018-Mar-10 0.4.0 2017-Mar-01 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
109 downloads total
-
- Score:
- 0.7
- Short URL:
- freck-streams.dub.pm