nsIOutputStream.idl 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is mozilla.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. * Warren Harris <[email protected]>
  24. * Darin Fisher <[email protected]>
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either of the GNU General Public License Version 2 or later (the "GPL"),
  28. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. #include "nsISupports.idl"
  40. interface nsIOutputStream;
  41. interface nsIInputStream;
  42. %{C++
  43. /**
  44. * The signature for the reader function passed to WriteSegments. This
  45. * is the "provider" of data that gets written into the stream's buffer.
  46. *
  47. * @param aOutStream stream being written to
  48. * @param aClosure opaque parameter passed to WriteSegments
  49. * @param aToSegment pointer to memory owned by the output stream
  50. * @param aFromOffset amount already written (since WriteSegments was called)
  51. * @param aCount length of toSegment
  52. * @param aReadCount number of bytes written
  53. *
  54. * Implementers should return the following:
  55. *
  56. * @return NS_OK and (*aReadCount > 0) if successfully provided some data
  57. * @return NS_OK and (*aReadCount = 0) or
  58. * @return <any-error> if not interested in providing any data
  59. *
  60. * Errors are never passed to the caller of WriteSegments.
  61. *
  62. * @status FROZEN
  63. */
  64. typedef NS_CALLBACK(nsReadSegmentFun)(nsIOutputStream *aOutStream,
  65. void *aClosure,
  66. char *aToSegment,
  67. PRUint32 aFromOffset,
  68. PRUint32 aCount,
  69. PRUint32 *aReadCount);
  70. %}
  71. native nsReadSegmentFun(nsReadSegmentFun);
  72. /**
  73. * nsIOutputStream
  74. *
  75. * @status FROZEN
  76. */
  77. [scriptable, uuid(0d0acd2a-61b4-11d4-9877-00c04fa0cf4a)]
  78. interface nsIOutputStream : nsISupports
  79. {
  80. /**
  81. * Close the stream. Forces the output stream to flush any buffered data.
  82. *
  83. * @throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking
  84. * the calling thread (non-blocking mode only)
  85. */
  86. void close();
  87. /**
  88. * Flush the stream.
  89. *
  90. * @throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking
  91. * the calling thread (non-blocking mode only)
  92. */
  93. void flush();
  94. /**
  95. * Write data into the stream.
  96. *
  97. * @param aBuf the buffer containing the data to be written
  98. * @param aCount the maximum number of bytes to be written
  99. *
  100. * @return number of bytes written (may be less than aCount)
  101. *
  102. * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
  103. * block the calling thread (non-blocking mode only)
  104. * @throws <other-error> on failure
  105. */
  106. unsigned long write(in string aBuf, in unsigned long aCount);
  107. /**
  108. * Writes data into the stream from an input stream.
  109. *
  110. * @param aFromStream the stream containing the data to be written
  111. * @param aCount the maximum number of bytes to be written
  112. *
  113. * @return number of bytes written (may be less than aCount)
  114. *
  115. * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
  116. * block the calling thread (non-blocking mode only)
  117. * @throws <other-error> on failure
  118. *
  119. * NOTE: This method is defined by this interface in order to allow the
  120. * output stream to efficiently copy the data from the input stream into
  121. * its internal buffer (if any). If this method was provided as an external
  122. * facility, a separate char* buffer would need to be used in order to call
  123. * the output stream's other Write method.
  124. */
  125. unsigned long writeFrom(in nsIInputStream aFromStream,
  126. in unsigned long aCount);
  127. /**
  128. * Low-level write method that has access to the stream's underlying buffer.
  129. * The reader function may be called multiple times for segmented buffers.
  130. * WriteSegments is expected to keep calling the reader until either there
  131. * is nothing left to write or the reader returns an error. WriteSegments
  132. * should not call the reader with zero bytes to provide.
  133. *
  134. * @param aReader the "provider" of the data to be written
  135. * @param aClosure opaque parameter passed to reader
  136. * @param aCount the maximum number of bytes to be written
  137. *
  138. * @return number of bytes written (may be less than aCount)
  139. *
  140. * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
  141. * block the calling thread (non-blocking mode only)
  142. * @throws <other-error> on failure
  143. *
  144. * NOTE: this function may be unimplemented if a stream has no underlying
  145. * buffer (e.g., socket output stream).
  146. */
  147. [noscript] unsigned long writeSegments(in nsReadSegmentFun aReader,
  148. in voidPtr aClosure,
  149. in unsigned long aCount);
  150. /**
  151. * @return true if stream is non-blocking
  152. *
  153. * NOTE: writing to a blocking output stream will block the calling thread
  154. * until all given data can be consumed by the stream.
  155. */
  156. boolean isNonBlocking();
  157. };