aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/io/multi_writer.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/io/multi_writer.v
downloadcli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/vlib/io/multi_writer.v')
-rw-r--r--v_windows/v/vlib/io/multi_writer.v33
1 files changed, 33 insertions, 0 deletions
diff --git a/v_windows/v/vlib/io/multi_writer.v b/v_windows/v/vlib/io/multi_writer.v
new file mode 100644
index 0000000..837ea30
--- /dev/null
+++ b/v_windows/v/vlib/io/multi_writer.v
@@ -0,0 +1,33 @@
+module io
+
+// new_multi_writer returns a Writer that writes to all writers. The write
+// function of the returned Writer writes to all writers of the MultiWriter,
+// returns the length of bytes written, and if any writer fails to write the
+// full length an error is returned and writing to other writers stops, and if
+// any writer returns an error the error is returned immediately and writing to
+// other writers stops.
+pub fn new_multi_writer(writers ...Writer) Writer {
+ return &MultiWriter{
+ writers: writers
+ }
+}
+
+// MultiWriter writes to all its writers.
+pub struct MultiWriter {
+pub mut:
+ writers []Writer
+}
+
+// write writes to all writers of the MultiWriter. Returns the length of bytes
+// written. If any writer fails to write the full length an error is returned
+// and writing to other writers stops. If any writer returns an error the error
+// is returned immediately and writing to other writers stops.
+pub fn (mut m MultiWriter) write(buf []byte) ?int {
+ for mut w in m.writers {
+ n := w.write(buf) ?
+ if n != buf.len {
+ return error('io: incomplete write to writer of MultiWriter')
+ }
+ }
+ return buf.len
+}