WAFileStream (Was: Re: [Seaside] VisualWorks + WebServers)
mkobetic at cincom.com
Wed Jul 25 19:03:11 UTC 2007
Avi Bryant wrote:
> On 7/25/07, Martin Kobetic <mkobetic at cincom.com> wrote:
>> On that note I'd like to mention one change that I felt compelled to
>> make. The WAFile class is designed to hold onto its contents as an
>> internal collection (ByteArray, String, whatever). I added a subclass
>> WAFileStream with the same API allowing to hold onto it as a stream.
>> That still allows using purely internal stream, but opens up the
>> possibility to use an external stream as well. This is obviously aimed
>> at being able to stream contents of a file straight from the socket to
>> the disk as the request is being parsed and then provide the WAFile
>> object on top of the new external stream. Would this kind of change be
>> something of interest ? Maybe for the ongoing 2.8 development effort ?
> That's definitely of interest, at least to me.
Great. For the sake of backward-compatibility the change is actually rather trivial.
Smalltalk.Seaside defineClass: #WAFileStream
'Minor modification of WAFile to hold the contents as stream, to avoid copying and bringing large content into memory unnecessarily.
!Seaside.WAFileStream methodsFor: 'accessing'!
^self stream reset; contents!
self stream: aByteArray readStream!
contents := aStream! !
This may be too trivial, depending on how often do you need to access the contents as #contents, which will make a copy of the contents every time. It might be interesting to try supporting a kind of a dual mode of existence as either the 'contents' or as the 'stream' depending on the accessors being used. However I suspect that to really take advantage of the external streams other parts may need to change to favor the stream accessors, otherwise all streams will quickly get converted to contents and be stuck in memory again.
More information about the Seaside