nsIFileStreams.idl 8.9 KB

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