|
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/. */ |
|
5 |
|
6 #include "nsIInputStream.idl" |
|
7 #include "nsIOutputStream.idl" |
|
8 |
|
9 interface nsIFile; |
|
10 |
|
11 /** |
|
12 * An input stream that allows you to read from a file. |
|
13 */ |
|
14 [scriptable, uuid(e3d56a20-c7ec-11d3-8cda-0060b0fc14a3)] |
|
15 interface nsIFileInputStream : nsIInputStream |
|
16 { |
|
17 /** |
|
18 * @param file file to read from |
|
19 * @param ioFlags file open flags listed in prio.h (see |
|
20 * PR_Open documentation) or -1 to open the |
|
21 * file in default mode (PR_RDONLY). |
|
22 * @param perm file mode bits listed in prio.h or -1 to |
|
23 * use the default value (0) |
|
24 * @param behaviorFlags flags specifying various behaviors of the class |
|
25 * (see enumerations in the class) |
|
26 */ |
|
27 void init(in nsIFile file, in long ioFlags, in long perm, |
|
28 in long behaviorFlags); |
|
29 |
|
30 /** |
|
31 * If this is set, the file will be deleted by the time the stream is |
|
32 * closed. It may be removed before the stream is closed if it is possible |
|
33 * to delete it and still read from it. |
|
34 * |
|
35 * If OPEN_ON_READ is defined, and the file was recreated after the first |
|
36 * delete, the file will be deleted again when it is closed again. |
|
37 */ |
|
38 const long DELETE_ON_CLOSE = 1<<1; |
|
39 |
|
40 /** |
|
41 * If this is set, the file will close automatically when the end of the |
|
42 * file is reached. |
|
43 */ |
|
44 const long CLOSE_ON_EOF = 1<<2; |
|
45 |
|
46 /** |
|
47 * If this is set, the file will be reopened whenever we reach the start of |
|
48 * the file, either by doing a Seek(0, NS_SEEK_CUR), or by doing a relative |
|
49 * seek that happen to reach the beginning of the file. If the file is |
|
50 * already open and the seek occurs, it will happen naturally. (The file |
|
51 * will only be reopened if it is closed for some reason.) |
|
52 */ |
|
53 const long REOPEN_ON_REWIND = 1<<3; |
|
54 |
|
55 /** |
|
56 * If this is set, the file will be opened (i.e., a call to |
|
57 * PR_Open done) only when we do an actual operation on the stream, |
|
58 * or more specifically, when one of the following is called: |
|
59 * - Seek |
|
60 * - Tell |
|
61 * - SetEOF |
|
62 * - Available |
|
63 * - Read |
|
64 * - ReadLine |
|
65 * |
|
66 * DEFER_OPEN is useful if we use the stream on a background |
|
67 * thread, so that the opening and possible |stat|ing of the file |
|
68 * happens there as well. |
|
69 * |
|
70 * @note Using this flag results in the file not being opened |
|
71 * during the call to Init. This means that any errors that might |
|
72 * happen when this flag is not set would happen during the |
|
73 * first read. Also, the file is not locked when Init is called, |
|
74 * so it might be deleted before we try to read from it. |
|
75 */ |
|
76 const long DEFER_OPEN = 1<<4; |
|
77 }; |
|
78 |
|
79 /** |
|
80 * An output stream that lets you stream to a file. |
|
81 */ |
|
82 [scriptable, uuid(e6f68040-c7ec-11d3-8cda-0060b0fc14a3)] |
|
83 interface nsIFileOutputStream : nsIOutputStream |
|
84 { |
|
85 /** |
|
86 * @param file file to write to |
|
87 * @param ioFlags file open flags listed in prio.h (see |
|
88 * PR_Open documentation) or -1 to open the |
|
89 * file in default mode (PR_WRONLY | |
|
90 * PR_CREATE_FILE | PR_TRUNCATE) |
|
91 * @param perm file mode bits listed in prio.h or -1 to |
|
92 * use the default permissions (0664) |
|
93 * @param behaviorFlags flags specifying various behaviors of the class |
|
94 * (currently none supported) |
|
95 */ |
|
96 void init(in nsIFile file, in long ioFlags, in long perm, |
|
97 in long behaviorFlags); |
|
98 |
|
99 /** |
|
100 * See the same constant in nsIFileInputStream. The deferred open will |
|
101 * be performed when one of the following is called: |
|
102 * - Seek |
|
103 * - Tell |
|
104 * - SetEOF |
|
105 * - Write |
|
106 * - Flush |
|
107 * |
|
108 * @note Using this flag results in the file not being opened |
|
109 * during the call to Init. This means that any errors that might |
|
110 * happen when this flag is not set would happen during the |
|
111 * first write, and if the file is to be created, then it will not |
|
112 * appear on the disk until the first write. |
|
113 */ |
|
114 const long DEFER_OPEN = 1<<0; |
|
115 }; |
|
116 |
|
117 /** |
|
118 * An input stream that allows you to read from a slice of a file. |
|
119 */ |
|
120 [scriptable, uuid(3ce03a2f-97f7-4375-b6bb-1788a60cad3b)] |
|
121 interface nsIPartialFileInputStream : nsISupports |
|
122 { |
|
123 /** |
|
124 * Initialize with a file and new start/end positions. Both start and |
|
125 * start+length must be smaller than the size of the file. Not doing so |
|
126 * will lead to undefined behavior. |
|
127 * You must initialize the stream, and only initialize it once, before it |
|
128 * can be used. |
|
129 * |
|
130 * @param file file to read from |
|
131 * @param start start offset of slice to read. Must be smaller |
|
132 * than the size of the file. |
|
133 * @param length length of slice to read. Must be small enough that |
|
134 * start+length is smaller than the size of the file. |
|
135 * @param ioFlags file open flags listed in prio.h (see |
|
136 * PR_Open documentation) or -1 to open the |
|
137 * file in default mode (PR_RDONLY). |
|
138 * @param perm file mode bits listed in prio.h or -1 to |
|
139 * use the default value (0) |
|
140 * @param behaviorFlags flags specifying various behaviors of the class |
|
141 * (see enumerations in nsIFileInputStream) |
|
142 */ |
|
143 void init(in nsIFile file, in unsigned long long start, |
|
144 in unsigned long long length, |
|
145 in long ioFlags, in long perm, in long behaviorFlags); |
|
146 }; |
|
147 |
|
148 /** |
|
149 * A stream that allows you to read from a file or stream to a file. |
|
150 */ |
|
151 [scriptable, uuid(82cf605a-8393-4550-83ab-43cd5578e006)] |
|
152 interface nsIFileStream : nsISupports |
|
153 { |
|
154 /** |
|
155 * @param file file to read from or stream to |
|
156 * @param ioFlags file open flags listed in prio.h (see |
|
157 * PR_Open documentation) or -1 to open the |
|
158 * file in default mode (PR_RDWR). |
|
159 * @param perm file mode bits listed in prio.h or -1 to |
|
160 * use the default value (0) |
|
161 * @param behaviorFlags flags specifying various behaviors of the class |
|
162 * (see enumerations in the class) |
|
163 */ |
|
164 void init(in nsIFile file, in long ioFlags, in long perm, |
|
165 in long behaviorFlags); |
|
166 |
|
167 /** |
|
168 * See the same constant in nsIFileInputStream. The deferred open will |
|
169 * be performed when one of the following is called: |
|
170 * - Seek |
|
171 * - Tell |
|
172 * - SetEOF |
|
173 * - Available |
|
174 * - Read |
|
175 * - Flush |
|
176 * - Write |
|
177 * - GetSize |
|
178 * - GetLastModified |
|
179 * |
|
180 * @note Using this flag results in the file not being opened |
|
181 * during the call to Init. This means that any errors that might |
|
182 * happen when this flag is not set would happen during the |
|
183 * first read or write. The file is not locked when Init is called, |
|
184 * so it might be deleted before we try to read from it and if the |
|
185 * file is to be created, then it will not appear on the disk until |
|
186 * the first write. |
|
187 */ |
|
188 const long DEFER_OPEN = 1<<0; |
|
189 }; |
|
190 |
|
191 /** |
|
192 * An interface that allows you to get some metadata like file size and |
|
193 * file last modified time. |
|
194 */ |
|
195 [scriptable, uuid(07f679e4-9601-4bd1-b510-cd3852edb881)] |
|
196 interface nsIFileMetadata : nsISupports |
|
197 { |
|
198 /** |
|
199 * File size in bytes; |
|
200 */ |
|
201 readonly attribute long long size; |
|
202 |
|
203 /** |
|
204 * File last modified time in milliseconds from midnight (00:00:00), |
|
205 * January 1, 1970 Greenwich Mean Time (GMT). |
|
206 */ |
|
207 readonly attribute long long lastModified; |
|
208 }; |