mirror of
https://github.com/gechandesu/runcmd.git
synced 2026-02-13 00:31:51 +03:00
breaking: revome ByteBuffer from API
This commit is contained in:
26
bytebuf.v
26
bytebuf.v
@@ -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
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user