From 8e7d757b3b7f3b50019e5a0ecf2771a6f1b20c53 Mon Sep 17 00:00:00 2001 From: ge Date: Thu, 29 Jan 2026 03:34:10 +0300 Subject: [PATCH] breaking: revome ByteBuffer from API --- bytebuf.v | 26 -------------------------- examples/write_to_child_stdin.v | 23 +++++++++++++++++++++-- 2 files changed, 21 insertions(+), 28 deletions(-) delete mode 100644 bytebuf.v diff --git a/bytebuf.v b/bytebuf.v deleted file mode 100644 index d64cf8f..0000000 --- a/bytebuf.v +++ /dev/null @@ -1,26 +0,0 @@ -module runcmd - -import io - -// buffer creates simple bytes buffer that can be read through `io.Reader` interface. -pub fn buffer(data []u8) ByteBuffer { - return ByteBuffer{ - bytes: data - } -} - -struct ByteBuffer { - bytes []u8 -mut: - pos int -} - -// read reads `buf.len` bytes from internal bytes buffer and returns number of bytes read. -pub fn (mut b ByteBuffer) read(mut buf []u8) !int { - if b.pos >= b.bytes.len { - return io.Eof{} - } - n := copy(mut buf, b.bytes[b.pos..]) - b.pos += n - return n -} diff --git a/examples/write_to_child_stdin.v b/examples/write_to_child_stdin.v index 09ce1ce..efa8915 100644 --- a/examples/write_to_child_stdin.v +++ b/examples/write_to_child_stdin.v @@ -1,6 +1,23 @@ +import io import strings import runcmd +struct ByteBuffer { + bytes []u8 +mut: + pos int +} + +// read reads `buf.len` bytes from internal bytes buffer and returns number of bytes read. +pub fn (mut b ByteBuffer) read(mut buf []u8) !int { + if b.pos >= b.bytes.len { + return io.Eof{} + } + n := copy(mut buf, b.bytes[b.pos..]) + b.pos += n + return n +} + fn main() { input := 'Hello from parent process!' @@ -8,8 +25,10 @@ fn main() { // * `reader` reads input from the parent process; it will be copied to the // standard input of the child process. // * `writer` accepts data from the child process; it will be copied from the - // standard output of the child process. - mut reader := runcmd.buffer(input.bytes()) + // standard output of the child process. This is optinal. + mut reader := ByteBuffer{ + bytes: input.bytes() + } mut writer := strings.new_builder(4096) // Prepare the command.