1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
15 * The Original Code is mozilla.org code.
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.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include
"nsISupports.idl"
40 interface nsIUnicharInputStream
;
41 interface nsIInputStream
;
45 * The signature of the writer function passed to ReadSegments. This
46 * is the "consumer" of data that gets read from the stream's buffer.
48 * @param aInStream stream being read
49 * @param aClosure opaque parameter passed to ReadSegments
50 * @param aFromSegment pointer to memory owned by the input stream
51 * @param aToOffset amount already read (since ReadSegments was called)
52 * @param aCount length of fromSegment
53 * @param aWriteCount number of bytes read
55 * Implementers should return the following:
57 * @return NS_OK and (*aWriteCount > 0) if consumed some data
58 * @return <any-error> if not interested in consuming any data
60 * Errors are never passed to the caller of ReadSegments.
62 * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior.
64 typedef NS_CALLBACK
(nsWriteUnicharSegmentFun
)(nsIUnicharInputStream
*aInStream
,
66 const PRUnichar
*aFromSegment
,
69 PRUint32
*aWriteCount
);
71 native nsWriteUnicharSegmentFun
(nsWriteUnicharSegmentFun
);
74 * Abstract unicode character input stream
77 [scriptable
, uuid(d5e3bd80
-6723-4b92
-b0c9
-22f6162fd94f
)]
78 interface nsIUnicharInputStream
: nsISupports
{
80 * Reads into a caller-provided character array.
82 * @return The number of characters that were successfully read. May be less
83 * than aCount, even if there is more data in the input stream.
84 * A return value of 0 means EOF.
86 * @note To read more than 2^32 characters, call this method multiple times.
88 [noscript
] unsigned long read
([array
, size_is(aCount
)] in PRUnichar aBuf
,
89 in unsigned long aCount
);
92 * Low-level read method that has access to the stream's underlying buffer.
93 * The writer function may be called multiple times for segmented buffers.
94 * ReadSegments is expected to keep calling the writer until either there is
95 * nothing left to read or the writer returns an error. ReadSegments should
96 * not call the writer with zero characters to consume.
98 * @param aWriter the "consumer" of the data to be read
99 * @param aClosure opaque parameter passed to writer
100 * @param aCount the maximum number of characters to be read
102 * @return number of characters read (may be less than aCount)
103 * @return 0 if reached end of file (or if aWriter refused to consume data)
105 * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
106 * block the calling thread (non-blocking mode only)
107 * @throws <other-error> on failure
109 * NOTE: this function may be unimplemented if a stream has no underlying
112 [noscript
] unsigned long readSegments
(in nsWriteUnicharSegmentFun aWriter
,
114 in unsigned long aCount
);
117 * Read into a string object.
118 * @param aCount The number of characters that should be read
119 * @return The number of characters that were read.
121 unsigned long readString
(in unsigned long aCount
, out AString aString
);
124 * Close the stream and free associated resources. This also closes the
125 * underlying stream, if any.