2017-02-04 12:49 GMT+01:00 Sven Van Caekenberghe <sven@stfx.eu>:
Hi Nicolai,
The FileSystem API is a bit inconsistent, yes.
This is how you can use it:
(FileLocator temp / 'foo.txt') writeStreamDo: [ :out | out binary. (ZnCharacterWriteStream on: out encoding: #utf8) << 'élève' ].
(FileLocator temp / 'foo.txt') readStreamDo: [ :in | in binary. ZnCharacterReadStream on: in encoding: #utf8) upToEnd ].
(FileLocator temp / 'foo.txt') binaryReadStreamDo: [ :in | (ZnCharacterReadStream on: in encoding: #utf8) upToEnd ].
There is no #binaryWriteStreamDo:
The API around File is more correct, IMHO.
Does this help ?
Yes, thanks for the fast response.
What exactly is your question ?
I am looking at the issues with FileList, there are some parts that don't work anymore (see FileList>>#contents, it calls some unimplemted methods), and it uses TextConverter and somoe parts of the older File api. It looks like most other (newer) parts are using ZnCharacterReadstream for encoding, but I couldn't find a way to use it together with FileReferences (most parts of the FileList already operate with the newer FileSystem API.
Sven
On 4 Feb 2017, at 12:09, Nicolai Hess <nicolaihess@gmail.com> wrote:
Hi How can I specify the character encoding when opening a readStream on a FileRerefence.
I found this, that works:
| readStream fileContent | readStream := (File named: aFileName) openForRead. fileContent := ZnCharacterReadStream on: readStream encoding: encoding. fileContent upToEnd asString.
But if I try to do the same with a readStream from a FileReference
| readStream fileContent | readStream := aFileName asFileReference readStream. fileContent := ZnCharacterReadStream on: readStream encoding: encoding. fileContent upToEnd asString.
I get an error SmallInteger DNU #asciiValue,
this is because, in the first method, we create a binary filestream, and if we use readStream from a FileReference, the stream is a MultibyteFileStream.
How can I us ZnEncoder for a readstream from a FileReference?
(and is it on purpose that both readStream method (openForRead/readStream) return different kinds of binary streams?)
nicolai