#FEATURE by exept
authorClaus Gittinger <cg@exept.de>
Mon, 22 Jul 2019 17:35:23 +0200
changeset 24454 9b9e7d371d89
parent 24453 042e5f43fdc5
child 24455 bbbbe36a470e
#FEATURE by exept class: Filename added: #readingFileWithEncoding:do:
Filename.st
--- a/Filename.st	Mon Jul 22 15:04:10 2019 +0200
+++ b/Filename.st	Mon Jul 22 17:35:23 2019 +0200
@@ -6748,6 +6748,30 @@
     "Modified: / 12-01-2018 / 18:21:32 / stefan"
 !
 
+readingFileWithEncoding:encodingNameSymbol do:aBlock
+    "Create a read stream on the receiver file, evaluate aBlock, passing that stream as arg,
+     and return the block's value.
+     If the file cannot be opened, an exception is raised or
+     (old behavior, will vanish:)the block is evaluated with a nil argument.
+     Ensures that the stream is closed.
+     The file is decoded on the fly."
+
+    ^ self readingFileDo:[:s |
+        aBlock value:(EncodedStream stream:s encoder:(CharacterEncoder encoderFor:encodingNameSymbol))
+    ].
+
+    "
+     'Make.proto' asFilename 
+        readingFileWithEncoding:#utf8 
+        do:[:stream |
+            stream upToEnd
+        ]
+    "
+
+
+    "Modified: / 12-01-2018 / 18:21:32 / stefan"
+!
+
 readingLinesDo:aBlock
     "Create a read stream on the receiver file and
      evaluate aBlock for each line read from the stream.