1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/public/nsIFileStreams.idl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,208 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsIInputStream.idl" 1.10 +#include "nsIOutputStream.idl" 1.11 + 1.12 +interface nsIFile; 1.13 + 1.14 +/** 1.15 + * An input stream that allows you to read from a file. 1.16 + */ 1.17 +[scriptable, uuid(e3d56a20-c7ec-11d3-8cda-0060b0fc14a3)] 1.18 +interface nsIFileInputStream : nsIInputStream 1.19 +{ 1.20 + /** 1.21 + * @param file file to read from 1.22 + * @param ioFlags file open flags listed in prio.h (see 1.23 + * PR_Open documentation) or -1 to open the 1.24 + * file in default mode (PR_RDONLY). 1.25 + * @param perm file mode bits listed in prio.h or -1 to 1.26 + * use the default value (0) 1.27 + * @param behaviorFlags flags specifying various behaviors of the class 1.28 + * (see enumerations in the class) 1.29 + */ 1.30 + void init(in nsIFile file, in long ioFlags, in long perm, 1.31 + in long behaviorFlags); 1.32 + 1.33 + /** 1.34 + * If this is set, the file will be deleted by the time the stream is 1.35 + * closed. It may be removed before the stream is closed if it is possible 1.36 + * to delete it and still read from it. 1.37 + * 1.38 + * If OPEN_ON_READ is defined, and the file was recreated after the first 1.39 + * delete, the file will be deleted again when it is closed again. 1.40 + */ 1.41 + const long DELETE_ON_CLOSE = 1<<1; 1.42 + 1.43 + /** 1.44 + * If this is set, the file will close automatically when the end of the 1.45 + * file is reached. 1.46 + */ 1.47 + const long CLOSE_ON_EOF = 1<<2; 1.48 + 1.49 + /** 1.50 + * If this is set, the file will be reopened whenever we reach the start of 1.51 + * the file, either by doing a Seek(0, NS_SEEK_CUR), or by doing a relative 1.52 + * seek that happen to reach the beginning of the file. If the file is 1.53 + * already open and the seek occurs, it will happen naturally. (The file 1.54 + * will only be reopened if it is closed for some reason.) 1.55 + */ 1.56 + const long REOPEN_ON_REWIND = 1<<3; 1.57 + 1.58 + /** 1.59 + * If this is set, the file will be opened (i.e., a call to 1.60 + * PR_Open done) only when we do an actual operation on the stream, 1.61 + * or more specifically, when one of the following is called: 1.62 + * - Seek 1.63 + * - Tell 1.64 + * - SetEOF 1.65 + * - Available 1.66 + * - Read 1.67 + * - ReadLine 1.68 + * 1.69 + * DEFER_OPEN is useful if we use the stream on a background 1.70 + * thread, so that the opening and possible |stat|ing of the file 1.71 + * happens there as well. 1.72 + * 1.73 + * @note Using this flag results in the file not being opened 1.74 + * during the call to Init. This means that any errors that might 1.75 + * happen when this flag is not set would happen during the 1.76 + * first read. Also, the file is not locked when Init is called, 1.77 + * so it might be deleted before we try to read from it. 1.78 + */ 1.79 + const long DEFER_OPEN = 1<<4; 1.80 +}; 1.81 + 1.82 +/** 1.83 + * An output stream that lets you stream to a file. 1.84 + */ 1.85 +[scriptable, uuid(e6f68040-c7ec-11d3-8cda-0060b0fc14a3)] 1.86 +interface nsIFileOutputStream : nsIOutputStream 1.87 +{ 1.88 + /** 1.89 + * @param file file to write to 1.90 + * @param ioFlags file open flags listed in prio.h (see 1.91 + * PR_Open documentation) or -1 to open the 1.92 + * file in default mode (PR_WRONLY | 1.93 + * PR_CREATE_FILE | PR_TRUNCATE) 1.94 + * @param perm file mode bits listed in prio.h or -1 to 1.95 + * use the default permissions (0664) 1.96 + * @param behaviorFlags flags specifying various behaviors of the class 1.97 + * (currently none supported) 1.98 + */ 1.99 + void init(in nsIFile file, in long ioFlags, in long perm, 1.100 + in long behaviorFlags); 1.101 + 1.102 + /** 1.103 + * See the same constant in nsIFileInputStream. The deferred open will 1.104 + * be performed when one of the following is called: 1.105 + * - Seek 1.106 + * - Tell 1.107 + * - SetEOF 1.108 + * - Write 1.109 + * - Flush 1.110 + * 1.111 + * @note Using this flag results in the file not being opened 1.112 + * during the call to Init. This means that any errors that might 1.113 + * happen when this flag is not set would happen during the 1.114 + * first write, and if the file is to be created, then it will not 1.115 + * appear on the disk until the first write. 1.116 + */ 1.117 + const long DEFER_OPEN = 1<<0; 1.118 +}; 1.119 + 1.120 +/** 1.121 + * An input stream that allows you to read from a slice of a file. 1.122 + */ 1.123 +[scriptable, uuid(3ce03a2f-97f7-4375-b6bb-1788a60cad3b)] 1.124 +interface nsIPartialFileInputStream : nsISupports 1.125 +{ 1.126 + /** 1.127 + * Initialize with a file and new start/end positions. Both start and 1.128 + * start+length must be smaller than the size of the file. Not doing so 1.129 + * will lead to undefined behavior. 1.130 + * You must initialize the stream, and only initialize it once, before it 1.131 + * can be used. 1.132 + * 1.133 + * @param file file to read from 1.134 + * @param start start offset of slice to read. Must be smaller 1.135 + * than the size of the file. 1.136 + * @param length length of slice to read. Must be small enough that 1.137 + * start+length is smaller than the size of the file. 1.138 + * @param ioFlags file open flags listed in prio.h (see 1.139 + * PR_Open documentation) or -1 to open the 1.140 + * file in default mode (PR_RDONLY). 1.141 + * @param perm file mode bits listed in prio.h or -1 to 1.142 + * use the default value (0) 1.143 + * @param behaviorFlags flags specifying various behaviors of the class 1.144 + * (see enumerations in nsIFileInputStream) 1.145 + */ 1.146 + void init(in nsIFile file, in unsigned long long start, 1.147 + in unsigned long long length, 1.148 + in long ioFlags, in long perm, in long behaviorFlags); 1.149 +}; 1.150 + 1.151 +/** 1.152 + * A stream that allows you to read from a file or stream to a file. 1.153 + */ 1.154 +[scriptable, uuid(82cf605a-8393-4550-83ab-43cd5578e006)] 1.155 +interface nsIFileStream : nsISupports 1.156 +{ 1.157 + /** 1.158 + * @param file file to read from or stream to 1.159 + * @param ioFlags file open flags listed in prio.h (see 1.160 + * PR_Open documentation) or -1 to open the 1.161 + * file in default mode (PR_RDWR). 1.162 + * @param perm file mode bits listed in prio.h or -1 to 1.163 + * use the default value (0) 1.164 + * @param behaviorFlags flags specifying various behaviors of the class 1.165 + * (see enumerations in the class) 1.166 + */ 1.167 + void init(in nsIFile file, in long ioFlags, in long perm, 1.168 + in long behaviorFlags); 1.169 + 1.170 + /** 1.171 + * See the same constant in nsIFileInputStream. The deferred open will 1.172 + * be performed when one of the following is called: 1.173 + * - Seek 1.174 + * - Tell 1.175 + * - SetEOF 1.176 + * - Available 1.177 + * - Read 1.178 + * - Flush 1.179 + * - Write 1.180 + * - GetSize 1.181 + * - GetLastModified 1.182 + * 1.183 + * @note Using this flag results in the file not being opened 1.184 + * during the call to Init. This means that any errors that might 1.185 + * happen when this flag is not set would happen during the 1.186 + * first read or write. The file is not locked when Init is called, 1.187 + * so it might be deleted before we try to read from it and if the 1.188 + * file is to be created, then it will not appear on the disk until 1.189 + * the first write. 1.190 + */ 1.191 + const long DEFER_OPEN = 1<<0; 1.192 +}; 1.193 + 1.194 +/** 1.195 + * An interface that allows you to get some metadata like file size and 1.196 + * file last modified time. 1.197 + */ 1.198 +[scriptable, uuid(07f679e4-9601-4bd1-b510-cd3852edb881)] 1.199 +interface nsIFileMetadata : nsISupports 1.200 +{ 1.201 + /** 1.202 + * File size in bytes; 1.203 + */ 1.204 + readonly attribute long long size; 1.205 + 1.206 + /** 1.207 + * File last modified time in milliseconds from midnight (00:00:00), 1.208 + * January 1, 1970 Greenwich Mean Time (GMT). 1.209 + */ 1.210 + readonly attribute long long lastModified; 1.211 +};