You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.


TOC PREV NEXT INDEX

Embedding Gecko API


nsIOutputStream


This interface manages writing data to an output stream. It is partially scriptable.

Methods
close

Closes the stream. Forces the output stream to flush any buffered data.

Syntax:

void nsIOutputStream::close() 

Parameters:

None.

nsresult:

NS_OK if successful.
Throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking the calling thread (non-blocking mode only)
flush

Flushes the stream.

Syntax:

void nsIOutputStream::flush() 

Parameters:

None.

nsresult:

NS_OK if successful.
Throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking the calling thread (non-blocking mode only).
write

Writes data into the stream from an input stream.

Syntax:

unsigned long nsIOutputStream::write(in string aBuf, 
	in unsigned long aCount) 

Parameters:

aBuf: The buffer containing the data to be written.
aCount: The maximum number of bytes to be written.

Returns:

The number of bytes written.
Throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking the calling thread (non-blocking mode only)
Throws <other-error> on failure.
writeFrom

Writes data into the stream from an input stream.

Syntax:

unsigned long nsIOutputStream::writeFrom(
	in nsIInputStream aFromStream,
	in unsigned long aCount) 

Parameters:

aFromStream:The stream containing the data to be written.
aCount: The maximum number of bytes to be written.

Returns:

The number of bytes written.
Throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking the calling thread (non-blocking mode only)
Throws <other-error> on failure

Note: This method is defined by this interface in order to allow the output stream to efficiently copy the data from the input stream into its internal buffer (if any). If this method was provided as an external facility, a separate char* buffer would need to be used in order to call the output stream's other Write method.

writeSegments

Low-level write method that has access to the stream's underlying buffer. The reader function may be called multiple times for segmented buffers. This method is not scriptable.

Syntax:

unsigned long nsIOutputStream::writeSegments(
	in nsReadSegmentFun aReader,
	in voidPtr aClosure,      
	in unsigned long aCount)  

Parameters:

aReader: The "provider" of the data to be written. The type is described below.
aClosure: Opaque parameter passed to reader.
aCount: The maximum number of bytes to be written.
typedef NS_CALLBACK(nsReadSegmentFun)(
		nsIOutputStream *aOutStream, 
		void *aClosure, 
		char *aToSegment, 
		PRUint32 aFromOffset, 
		PRUint32 aCount, 
		PRUint32 *aReadCount) 

aOutStream: The stream being written to.
aClosure: Opaque parameter passed to writeSegments.
aToSegment: A pointer to memory owned by the output stream.
aFromOffset: The amount already written (since writeSegments was called).
aCount: The length of toSegment.
aReadCount: The number of bytes written.

Note: Implementers should return the following: NS_OK and (*aReadCount > 0) if successfully provided some data; NS_OK and (*aReadCount = 0); or NS_BASE_STREAM_WOULD_BLOCK if not interested in providing any data;<other-error> on failure

Errors are passed to the caller of writeSegments, unless aFromOffset is greater than zero.

Returns:

The number of bytes written.
Throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would block the calling thread (non-blocking mode only).
Throws <other-error> on failure.

Note: this function may be unimplemented if a stream has no underlying buffer (e.g., socket output stream).

isNonBlocking

Returns TRUE if stream is non-blocking.

Syntax:

boolean nsIOutputStream::isNonBlocking() 

Parameters:

None.

Returns:

TRUE if stream is non-blocking.
FALSE otherwise.

Written by:Ellen Evans | Comments, questions, complaints? Bug 143387
TOC PREV NEXT INDEX