Bumping manifests a=b2g-bump
[gecko.git] / xpcom / io / nsIOutputStream.idl
blobea0a849f595ab3a14c5eaf7933ee8254c85c4690
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsISupports.idl"
8 interface nsIOutputStream;
9 interface nsIInputStream;
11 %{C++
12 /**
13 * The signature for the reader function passed to WriteSegments. This
14 * is the "provider" of data that gets written into the stream's buffer.
16 * @param aOutStream stream being written to
17 * @param aClosure opaque parameter passed to WriteSegments
18 * @param aToSegment pointer to memory owned by the output stream
19 * @param aFromOffset amount already written (since WriteSegments was called)
20 * @param aCount length of toSegment
21 * @param aReadCount number of bytes written
23 * Implementers should return the following:
25 * @throws <any-error> if not interested in providing any data
27 * Errors are never passed to the caller of WriteSegments.
29 typedef NS_CALLBACK(nsReadSegmentFun)(nsIOutputStream *aOutStream,
30 void *aClosure,
31 char *aToSegment,
32 uint32_t aFromOffset,
33 uint32_t aCount,
34 uint32_t *aReadCount);
37 native nsReadSegmentFun(nsReadSegmentFun);
39 /**
40 * nsIOutputStream
42 * An interface describing a writable stream of data. An output stream may be
43 * "blocking" or "non-blocking" (see the IsNonBlocking method). A blocking
44 * output stream may suspend the calling thread in order to satisfy a call to
45 * Close, Flush, Write, WriteFrom, or WriteSegments. A non-blocking output
46 * stream, on the other hand, must not block the calling thread of execution.
48 * NOTE: blocking output streams are often written to on a background thread to
49 * avoid locking up the main application thread. For this reason, it is
50 * generally the case that a blocking output stream should be implemented using
51 * thread- safe AddRef and Release.
53 [scriptable, uuid(0d0acd2a-61b4-11d4-9877-00c04fa0cf4a)]
54 interface nsIOutputStream : nsISupports
56 /**
57 * Close the stream. Forces the output stream to flush any buffered data.
59 * @throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking
60 * the calling thread (non-blocking mode only)
62 void close();
64 /**
65 * Flush the stream.
67 * @throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking
68 * the calling thread (non-blocking mode only)
70 void flush();
72 /**
73 * Write data into the stream.
75 * @param aBuf the buffer containing the data to be written
76 * @param aCount the maximum number of bytes to be written
78 * @return number of bytes written (may be less than aCount)
80 * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
81 * block the calling thread (non-blocking mode only)
82 * @throws <other-error> on failure
84 unsigned long write(in string aBuf, in unsigned long aCount);
86 /**
87 * Writes data into the stream from an input stream.
89 * @param aFromStream the stream containing the data to be written
90 * @param aCount the maximum number of bytes to be written
92 * @return number of bytes written (may be less than aCount)
94 * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
95 * block the calling thread (non-blocking mode only). This failure
96 * means no bytes were transferred.
97 * @throws <other-error> on failure
99 * NOTE: This method is defined by this interface in order to allow the
100 * output stream to efficiently copy the data from the input stream into
101 * its internal buffer (if any). If this method was provided as an external
102 * facility, a separate char* buffer would need to be used in order to call
103 * the output stream's other Write method.
105 unsigned long writeFrom(in nsIInputStream aFromStream,
106 in unsigned long aCount);
109 * Low-level write method that has access to the stream's underlying buffer.
110 * The reader function may be called multiple times for segmented buffers.
111 * WriteSegments is expected to keep calling the reader until either there
112 * is nothing left to write or the reader returns an error. WriteSegments
113 * should not call the reader with zero bytes to provide.
115 * @param aReader the "provider" of the data to be written
116 * @param aClosure opaque parameter passed to reader
117 * @param aCount the maximum number of bytes to be written
119 * @return number of bytes written (may be less than aCount)
121 * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
122 * block the calling thread (non-blocking mode only). This failure
123 * means no bytes were transferred.
124 * @throws NS_ERROR_NOT_IMPLEMENTED if the stream has no underlying buffer
125 * @throws <other-error> on failure
127 * NOTE: this function may be unimplemented if a stream has no underlying
128 * buffer (e.g., socket output stream).
130 [noscript] unsigned long writeSegments(in nsReadSegmentFun aReader,
131 in voidPtr aClosure,
132 in unsigned long aCount);
135 * @return true if stream is non-blocking
137 * NOTE: writing to a blocking output stream will block the calling thread
138 * until all given data can be consumed by the stream.
140 * NOTE: a non-blocking output stream may implement nsIAsyncOutputStream to
141 * provide consumers with a way to wait for the stream to accept more data
142 * once its write method is unable to accept any data without blocking.
144 boolean isNonBlocking();