how to -- buffered read / write to stdio

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how to -- buffered read / write to stdio

Pharo Smalltalk Users mailing list
From — "Pharo 7 file streams guideline"

https://github.com/pavel-krivanek/pharoMaterials/blob/master/Filestreams.MD


I have some ideas like —

   in := ZnFastLineReader on:       (ZnCharacterReadStream on: Stdio stdin).   out := ZnBufferedWriteStream on:
      (ZnCharacterWriteStream on: Stdio stdout).


What would be faster / better / more Pharo ways to do buffered reads and buffered writes to stdio ?

Reply | Threaded
Open this post in threaded view
|

Re: how to -- buffered read / write to stdio

Alistair Grant
Hi Isaac,

On Wed, 27 Mar 2019 at 17:18, Isaac Gouy via Pharo-users
<[hidden email]> wrote:

>
> From — "Pharo 7 file streams guideline"
>
> https://github.com/pavel-krivanek/pharoMaterials/blob/master/Filestreams.MD
>
>
> I have some ideas like —
>
>    in := ZnFastLineReader on:       (ZnCharacterReadStream on: Stdio stdin).   out := ZnBufferedWriteStream on:
>       (ZnCharacterWriteStream on: Stdio stdout).
>
>
> What would be faster / better / more Pharo ways to do buffered reads and buffered writes to stdio ?

This is heading in the right direction.  The buffered wrappers are
normally placed on the underlying binary stream, and then wrapped with
the encoder / decoder.  Follow through FileReference>>writeStream and
FileReference>>readStream to see how it is done for files.

in := ZnFastLineReader on: (ZnCharacterReadStream on:
(ZnBufferedReadStream on: Stdio stdin)).

out := ZnCharacterWriteStream on: (ZnBufferedWriteStream on: Stdio stdout).

Note that if you're doing terminal IO you'll need to handle stdin differently.

If you're writing to a terminal on Linux / MacOS you'll need to use
LFs instead of Pharo's standard CRs, so it may be worthwhile adding
ZnNewLineWriterStream on: out.

HTH,
Alistair