netwerk/base/public/nsIFileStreams.idl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial