~sircmpwn/hare-users

3

how to write buffer in teestream?

Details
Message ID
<CADVGtmtGYrs8T24mMkiPrOu7+0g2SkrhNUiahJpZc13FZz_LuQ@mail.gmail.com>
DKIM signature
pass
Download raw message
use fmt;
use io;
use bufio;
use memio;
use os;
use fs;
use strings;

export fn main() void = {

   const input = os::stdin;
   const file = os::create("out.txt", fs::mode::USER_RW)!;
   const ttt = io::tee(input, file); // create teestream

   const buf = strings::toutf8("hello");
   io::write(&ttt, buf)!;

};

I am getting an error:
Aborted (core dumped)

Could anybody say what I am doing wrong?
Details
Message ID
<CADVGtmtuvShTzTSQ8S-A8n31djutgmeSzrnPJZGSYODWxM=-fw@mail.gmail.com>
In-Reply-To
<CADVGtmtGYrs8T24mMkiPrOu7+0g2SkrhNUiahJpZc13FZz_LuQ@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
Oh... It seems that I was need to use:
const input = os::stdout; // not stdin

ср, 31 янв. 2024 г. в 13:02, Dmitry B <bubnenkoff@gmail.com>:
>
> use fmt;
> use io;
> use bufio;
> use memio;
> use os;
> use fs;
> use strings;
>
> export fn main() void = {
>
>    const input = os::stdin;
>    const file = os::create("out.txt", fs::mode::USER_RW)!;
>    const ttt = io::tee(input, file); // create teestream
>
>    const buf = strings::toutf8("hello");
>    io::write(&ttt, buf)!;
>
> };
>
> I am getting an error:
> Aborted (core dumped)
>
> Could anybody say what I am doing wrong?
Details
Message ID
<CADVGtmspdLOBKs7gJ3rd8WPE+t4htZ3PzTR+tr+XwJ8WH70HOg@mail.gmail.com>
In-Reply-To
<CADVGtmtuvShTzTSQ8S-A8n31djutgmeSzrnPJZGSYODWxM=-fw@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
export fn main() void = {

   const input = os::stdout;
   const file = os::create("out.txt", fs::mode::USER_RW)!;
   const ttt = io::tee(input, file); // create teestream

   const buf = strings::toutf8("hello");
   io::write(&ttt, buf)!;

   // which copies writes and **reads** into 'sink'
   const res = io::drain(&ttt); // is it reads operation?
   // if yes then why no hellohello in out.txt?
};



ср, 31 янв. 2024 г. в 13:06, Dmitry B <bubnenkoff@gmail.com>:
>
> Oh... It seems that I was need to use:
> const input = os::stdout; // not stdin
>
> ср, 31 янв. 2024 г. в 13:02, Dmitry B <bubnenkoff@gmail.com>:
> >
> > use fmt;
> > use io;
> > use bufio;
> > use memio;
> > use os;
> > use fs;
> > use strings;
> >
> > export fn main() void = {
> >
> >    const input = os::stdin;
> >    const file = os::create("out.txt", fs::mode::USER_RW)!;
> >    const ttt = io::tee(input, file); // create teestream
> >
> >    const buf = strings::toutf8("hello");
> >    io::write(&ttt, buf)!;
> >
> > };
> >
> > I am getting an error:
> > Aborted (core dumped)
> >
> > Could anybody say what I am doing wrong?
Details
Message ID
<CADVGtmvfDoAqQFxzmGBNViD+_1KH+pkNNsJ=skoiURD1gQk4-g@mail.gmail.com>
In-Reply-To
<CADVGtmspdLOBKs7gJ3rd8WPE+t4htZ3PzTR+tr+XwJ8WH70HOg@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
I decided that I should try to do read operation from handler:

export fn main() void = {

   const dyn_handler = memio::dynamic();

   const file = os::create("out.txt", fs::mode::USER_RW)!;
   const ttt = io::tee(&dyn_handler, file); // create teestream

   const line = bufio::read_line(os::stdin)! as []u8;
   io::write(&ttt, line)!;
   const r = io::drain(&dyn_handler);
};

I expected that line:
const r = io::drain(&dyn_handler);
is write into the sink because: "which copies writes and **reads** into 'sink'"

But it don't.

ср, 31 янв. 2024 г. в 14:08, Dmitry B <bubnenkoff@gmail.com>:
>
> export fn main() void = {
>
>    const input = os::stdout;
>    const file = os::create("out.txt", fs::mode::USER_RW)!;
>    const ttt = io::tee(input, file); // create teestream
>
>    const buf = strings::toutf8("hello");
>    io::write(&ttt, buf)!;
>
>    // which copies writes and **reads** into 'sink'
>    const res = io::drain(&ttt); // is it reads operation?
>    // if yes then why no hellohello in out.txt?
> };
>
>
>
> ср, 31 янв. 2024 г. в 13:06, Dmitry B <bubnenkoff@gmail.com>:
> >
> > Oh... It seems that I was need to use:
> > const input = os::stdout; // not stdin
> >
> > ср, 31 янв. 2024 г. в 13:02, Dmitry B <bubnenkoff@gmail.com>:
> > >
> > > use fmt;
> > > use io;
> > > use bufio;
> > > use memio;
> > > use os;
> > > use fs;
> > > use strings;
> > >
> > > export fn main() void = {
> > >
> > >    const input = os::stdin;
> > >    const file = os::create("out.txt", fs::mode::USER_RW)!;
> > >    const ttt = io::tee(input, file); // create teestream
> > >
> > >    const buf = strings::toutf8("hello");
> > >    io::write(&ttt, buf)!;
> > >
> > > };
> > >
> > > I am getting an error:
> > > Aborted (core dumped)
> > >
> > > Could anybody say what I am doing wrong?
Reply to thread Export thread (mbox)