3.7/3.8 FileStream compatibility and Seaside/KomHttpServer

Ned Konz ned at squeakland.org
Sun Mar 6 18:21:20 UTC 2005


On Sunday 06 March 2005 9:14 am, Yoshiki Ohshima wrote:
>   Depending on what you want it to do, one way the portion of code
> should like is:
>
> fileStream _ FileDirectory default readOnlyFileNamed: fullFilePath.
> fileStream ifNil: [^ false].
> HttpResponse current: (HttpResponse
>                         fromStream: (fileStream binary contentsOfEntireFile
> readStream).
>
>   The idea is to use #binary where the code shouldn't do
> anything with encodings of the file contents.
>
>   I haven't tried this code, so don't know if you can use a binary
> stream there, though.  (But it should.)

Rather than slurping the entire file into memory, why not just

fileStream := FileDirectory default readOnlyFileNamed: fullFilePath.
fileStream ifNil: [^ false].
fileStream converter: nil.
HttpResponse current: (HttpResponse fromStream: fileStream.


or even:


fileStream := StandardFileStream readOnlyFileNamed: (FileDirectory default 
fullNameFor: fullFilePath).
fileStream ifNil: [^ false].
HttpResponse current: (HttpResponse fromStream: fileStream).


The problem with calling #binary is that it changes the interface to the 
stream: #next and #next: return SmallInteger and ByteArray objects instead of 
Character and String objects.

-- 
Ned Konz
http://bike-nomad.com/squeak/



More information about the Squeak-dev mailing list