1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 nsIUnicharInputStream
;
9 interface nsIInputStream
;
13 * The signature of the writer function passed to ReadSegments. This
14 * is the "consumer" of data that gets read from the stream's buffer.
16 * @param aInStream stream being read
17 * @param aClosure opaque parameter passed to ReadSegments
18 * @param aFromSegment pointer to memory owned by the input stream
19 * @param aToOffset amount already read (since ReadSegments was called)
20 * @param aCount length of fromSegment
21 * @param aWriteCount number of bytes read
23 * Implementers should return the following:
25 * @throws <any-error> if not interested in consuming any data
27 * Errors are never passed to the caller of ReadSegments.
29 * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior.
31 typedef nsresult
(*nsWriteUnicharSegmentFun
)(nsIUnicharInputStream
*aInStream
,
33 const char16_t
*aFromSegment
,
36 uint32_t
*aWriteCount
);
38 native nsWriteUnicharSegmentFun
(nsWriteUnicharSegmentFun
);
41 * Abstract unicode character input stream
44 [scriptable
, uuid(d5e3bd80
-6723-4b92
-b0c9
-22f6162fd94f
)]
45 interface nsIUnicharInputStream
: nsISupports
{
47 * Reads into a caller-provided character array.
49 * @return The number of characters that were successfully read. May be less
50 * than aCount, even if there is more data in the input stream.
51 * A return value of 0 means EOF.
53 * @note To read more than 2^32 characters, call this method multiple times.
55 [noscript
] unsigned long read
([array
, size_is(aCount
)] in char16_t aBuf
,
56 in unsigned long aCount
);
59 * Low-level read method that has access to the stream's underlying buffer.
60 * The writer function may be called multiple times for segmented buffers.
61 * ReadSegments is expected to keep calling the writer until either there is
62 * nothing left to read or the writer returns an error. ReadSegments should
63 * not call the writer with zero characters to consume.
65 * @param aWriter the "consumer" of the data to be read
66 * @param aClosure opaque parameter passed to writer
67 * @param aCount the maximum number of characters to be read
69 * @return number of characters read (may be less than aCount)
70 * @return 0 if reached end of file (or if aWriter refused to consume data)
72 * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
73 * block the calling thread (non-blocking mode only)
74 * @throws <other-error> on failure
76 * NOTE: this function may be unimplemented if a stream has no underlying
79 [noscript
] unsigned long readSegments
(in nsWriteUnicharSegmentFun aWriter
,
81 in unsigned long aCount
);
84 * Read into a string object.
85 * @param aCount The number of characters that should be read
86 * @return The number of characters that were read.
88 unsigned long readString
(in unsigned long aCount
, out AString aString
);
91 * Close the stream and free associated resources. This also closes the
92 * underlying stream, if any.