iopipe: Writing output to std.io File
Jesse Phillips
Jesse.K.Phillips+D at gmail.com
Tue Jan 28 06:25:56 UTC 2020
On Monday, 27 January 2020 at 18:12:40 UTC, Steven Schveighoffer
wrote:
> Before I show you what to do, let me explain what the above
> actually does.
>
> 1. You constructed a buffer of characters. Good, this is the
> first step.
> 2. You used encodeText to convert the data to ubyte. Note that
> for char buffer, this basically is just a cast. Other encodings
> might do byteswapping. But you have done this step a bit early.
> At this point now, the window type is ubyte[]. You want to put
> data into the buffer as char[].
> 3. You appended an outputPipe, which is a pass through while
> writing the data to a file (which is fed a stream of
> uninitialized data I think, so you probably got a file with
> garbage in it). Writing to this pipe's buffer is kind of
> pointless because the writing has already happened (pretty much
> all effects and actions performed on the buffer happen in the
> .extend function).
>
> What you need is to access the buffer for writing BEFORE
> encoding and streaming to the file. For this, you need the push
> [1] mechanism, which wraps up everything you want to happen to
> data you have written to the buffer into a lambda template:
>
> auto outputBuffered = bufd!char
> .push!(p => p
> .encodeText
> .outputPipe(output()));
>
> [1] http://schveiguy.github.io/iopipe/iopipe/valve/push.html
I really feel like this is all very well thought out and clean, I
don't appear to have a previous model to help visualize this
output approach. Right now something like tee is coming to mind.
Thank you for explaining with the answer.
More information about the Digitalmars-d-learn
mailing list