mirror of
https://github.com/gechandesu/runcmd.git
synced 2026-02-13 08:41: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 strings
|
||||||
import runcmd
|
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() {
|
fn main() {
|
||||||
input := 'Hello from parent process!'
|
input := 'Hello from parent process!'
|
||||||
|
|
||||||
@@ -8,8 +25,10 @@ fn main() {
|
|||||||
// * `reader` reads input from the parent process; it will be copied to the
|
// * `reader` reads input from the parent process; it will be copied to the
|
||||||
// standard input of the child process.
|
// standard input of the child process.
|
||||||
// * `writer` accepts data from the child process; it will be copied from the
|
// * `writer` accepts data from the child process; it will be copied from the
|
||||||
// standard output of the child process.
|
// standard output of the child process. This is optinal.
|
||||||
mut reader := runcmd.buffer(input.bytes())
|
mut reader := ByteBuffer{
|
||||||
|
bytes: input.bytes()
|
||||||
|
}
|
||||||
mut writer := strings.new_builder(4096)
|
mut writer := strings.new_builder(4096)
|
||||||
|
|
||||||
// Prepare the command.
|
// Prepare the command.
|
||||||
|
|||||||
Reference in New Issue
Block a user