[Pharo-users] Pharo 7 streams API

Ben Coman btc at openinworld.com
Sat Jun 23 21:08:50 EDT 2018


On 24 June 2018 at 00:53, Sven Van Caekenberghe <sven at stfx.eu> wrote:

> Peter,
>
> > On 23 Jun 2018, at 15:39, Peter Uhnák <i.uhnak at gmail.com> wrote:
> >
> > Hi,
> >
> > I'm starting to familiarize myself with new streams, and one thing I've
> noticed is the removal of #lineEndConvention (which I use all the time).
> >
> > So a statement like this
> >
> > aFile writeStreamDo: [ :stream |
> >       stream lineEndConvention: #lf.
> >       stream << '...'
> > ].
> >
> > has to be written like so
> >
> > aFile writeStreamDo: [ :rawStream | |stream|
> >       stream := (ZnNewLineWriterStream on: rawStream) forLf.
> >       stream << '...'
> > ].
> >
> > which feels very messy because I am mixing writing with the
> configuration. And I don't even take account for buffered/encoded
> decorators. Plus it increases the incidental complexity -- I need another
> variable, and I can accidentally write to the wrong stream, etc.
> >
> > Would a method like #writeStream:do: (or #writeStreamTransform:do:) make
> sense? E.g.
> >
> > aFile writeStreamTransform: [ :stream | (ZnNewLineWriterStream on:
> stream) ] do: [ :stream |
> >       stream << '...'
> > ]
> >
> > To separate the composition from the usage?
> >
> > Thanks,
> > Peter
>
> The goals of the 'new' (they have existed for quite a while) streams is to
> go from single big complex do all classes and replace that with a
> composition of much simpler single purpose classes. Another goal is to
> reduce the API so that it becomes easier to create new stream classes. Of
> course, a consequence is that you need composition to get the functionality
> you want. But I think you understand the tradeoff.
>
> If the mixing of configuration/setup with writing/reading bothers you,
> then I would suggest using two methods. One that does only the
> writing/reading assuming a limited API, and another that does the
> configuration/setup, using composition.
>
> Note that the streams that you get already are a composition (most often a
> BinaryFileStream wrapped in a Buffered stream wrapped in a
> Encoding/Decoding stream). EOL translation is not a standard part of that.
> But there is quite some system code that does uses EOL translation.


There may be performance implications for streams opened frequently, but
perhaps something like this would be useful...??
  aFile writeStreamDo: [ :stream |
       stream becomeWrappedBy: ( ZnNewLineWriterStream new forLf).
       stream << '...'

cheers -ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20180624/b1b1a9f3/attachment.html>


More information about the Pharo-users mailing list