|
Output Object |
|
See Also: |
The Output.Buffer property sets/returns whether or not the output stream is buffered.
VBScript:
JScript:
| boolVal | True: Data written to the Output object is held in a buffer. This buffer can be cleared, or it can be flushed to the output stream. False (Default): Data is written directly to the output stream. |
Output buffering allows generated content to be cleared or committed, subsequent to content generation. This supports selective inclusion or omission of blocks of content. Buffering can also be used to minimize the amount of time the output file is open.
When Output.Buffer is True, all generated content is stored in a buffer. Once content is stored in the buffer, it can be flushed or cleared. Output.FlushBuffer() sends the entire buffer contents to the output stream, and then clears the buffer. Output.ClearBuffer() clears the buffer, erasing any buffered content. The contents of the buffer can be retrieved or replaced using the Output.BufferContents property.
If the Output.Buffer property is True when Output.Open() is called, and Output.Append is false, the opening/creation of the physical output file is delayed. The buffer is opened, but the physical output file is not opened until the first time the buffer is flushed. It is often desirable to minimize the amount of time that an output file is open, eliminating the chance of a file being read when it is only partially generated. For example, when writing to a web server directory, you may want to ensure that incomplete files are never served, and files are held open for as short a period as possible. Setting Output.Buffer to True accomplishes both these things.
The following example uses Output.Buffer, Output.FlushBuffer(), and Output.ClearBuffer():
<%#
Output.Filename = "TestBuffer.htm"
' This first block of content is not
' buffered, so it will be sent to
' the output file
#%>
<HTML><BODY>
Testing Output.Buffer...
<%#
Output.Buffer = True
' Following content is buffered
#%>
<P>Paragraph #1</P>
<%#
' Let's use Paragraph #1
Output.FlushBuffer()
#%>
<P>Paragraph #2</P>
<%#
' Let's not use Paragraph #2
Output.ClearBuffer()
#%>
<P>Paragraph #3</P>
<%#
' Let's turn off buffering
' Since Paragraph #3 is still in the buffer,
' it will be flushed.
Output.Buffer = False
#%>
</BODY></HTML>
This example produces the following output:
<HTML><BODY>
Testing Output.Buffer...
<P>Paragraph #1</P>
<P>Paragraph #3</P>
</BODY></HTML>