Add support for writing strings to existing files through YFile stream
This commit is contained in:
parent
228d8f57cb
commit
38f1ba3900
|
@ -32,6 +32,7 @@ interface YStream
|
||||||
{
|
{
|
||||||
void writeExact(const void* buffer, size_t size);
|
void writeExact(const void* buffer, size_t size);
|
||||||
size_t write(const(ubyte)[] buffer);
|
size_t write(const(ubyte)[] buffer);
|
||||||
|
size_t write(const(char)[] str);
|
||||||
void flush();
|
void flush();
|
||||||
@property bool writeable();
|
@property bool writeable();
|
||||||
}
|
}
|
||||||
|
@ -51,6 +52,11 @@ class YMemoryStream : YStream
|
||||||
return buffer.length;
|
return buffer.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t write(const(char)[] str)
|
||||||
|
{
|
||||||
|
return write(cast(const(ubyte)[])str);
|
||||||
|
}
|
||||||
|
|
||||||
void flush() {}
|
void flush() {}
|
||||||
|
|
||||||
@property bool writeable() { return true; }
|
@property bool writeable() { return true; }
|
||||||
|
@ -66,6 +72,18 @@ class YFile : YStream
|
||||||
this.file = std.stdio.File(fn, "w");
|
this.file = std.stdio.File(fn, "w");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this(std.stdio.File file)
|
||||||
|
{
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
import std.stdio : stdout;
|
||||||
|
auto stream = new YFile(stdout);
|
||||||
|
stream.write("Test writing to stdout through YFile stream\n");
|
||||||
|
}
|
||||||
|
|
||||||
void writeExact(const void* buffer, size_t size)
|
void writeExact(const void* buffer, size_t size)
|
||||||
{
|
{
|
||||||
this.file.rawWrite(cast(const) buffer[0 .. size]);
|
this.file.rawWrite(cast(const) buffer[0 .. size]);
|
||||||
|
@ -77,6 +95,11 @@ class YFile : YStream
|
||||||
return buffer.length;
|
return buffer.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t write(const(char)[] str)
|
||||||
|
{
|
||||||
|
return write(cast(const(ubyte)[])str);
|
||||||
|
}
|
||||||
|
|
||||||
void flush()
|
void flush()
|
||||||
{
|
{
|
||||||
this.file.flush();
|
this.file.flush();
|
||||||
|
|
Loading…
Reference in a new issue