On 4 Oct 2017, at 09:23, Dirk Olmes <dirk@xanthippe.ping.de> wrote:
Hi Sven,
I'm trying to get started with Pharo doing something really simple - at least that's what I thought ... I'm trying to read a text file line by line.
If I use File named: '/tmp/linex.txt' readStream nextLine I'll get a debugger telling me that BinaryFileStream does not understand nextLine.
(File named: '/tmp/lines.txt') readStreamDo: [ :in | | characterStream | characterStream := ZnCharacterReadStream on: in. Array streamContents: [ :out | [ characterStream atEnd ] whileFalse: [ out nextPut: characterStream nextLine ] ] ].
Thanks for the hint, Sven. Of all alternatives you gave I like the last one best as it does not load the entire contents of the (probably large) text file into memory.
Yes, that is true, the first ones are more for quick and dirty scripting, real streaming is better for production code.
ZnCharacterReadStream belongs to the Zinc classes. I would have expected a generic character reading stream to be part of the core classes (whatever that means :-) and not a part of some HTTP component classes. But that may only be my limited understanding of Pharo so far :-)
Well, the package is 'Zinc-Character-Encoding-Core' not 'Zinc-HTTP'. Character encoding stands on its own and has nothing to do with HTTP. See also this book chapter https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBook/lastSuccessfu...
-dirk