aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/vlib/io/readerwriter.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/old/vlib/io/readerwriter.v
downloadcli-tools-windows-master.tar.gz
cli-tools-windows-master.tar.bz2
cli-tools-windows-master.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/old/vlib/io/readerwriter.v')
-rw-r--r--v_windows/v/old/vlib/io/readerwriter.v34
1 files changed, 34 insertions, 0 deletions
diff --git a/v_windows/v/old/vlib/io/readerwriter.v b/v_windows/v/old/vlib/io/readerwriter.v
new file mode 100644
index 0000000..ba44172
--- /dev/null
+++ b/v_windows/v/old/vlib/io/readerwriter.v
@@ -0,0 +1,34 @@
+module io
+
+// ReaderWriter represents a stream that can be read from and wrote to
+pub interface ReaderWriter {
+ // from Reader
+ read(mut buf []byte) ?int
+ // from Writer
+ write(buf []byte) ?int
+}
+
+// ReaderWriterImpl is a ReaderWriter that can be made from
+// a seperate reader and writer (see fn make_readerwriter)
+struct ReaderWriterImpl {
+ r Reader
+mut:
+ w Writer
+}
+
+pub fn (mut r ReaderWriterImpl) read(mut buf []byte) ?int {
+ return r.r.read(mut buf)
+}
+
+pub fn (mut r ReaderWriterImpl) write(buf []byte) ?int {
+ return r.w.write(buf)
+}
+
+// make_readerwriter takes a rstream and a wstream and makes
+// an rwstream with them
+pub fn make_readerwriter(r Reader, w Writer) ReaderWriterImpl {
+ return ReaderWriterImpl{
+ r: r
+ w: w
+ }
+}