michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsIInputStream.idl" michael@0: #include "nsIOutputStream.idl" michael@0: michael@0: interface nsIFile; michael@0: michael@0: /** michael@0: * An input stream that allows you to read from a file. michael@0: */ michael@0: [scriptable, uuid(e3d56a20-c7ec-11d3-8cda-0060b0fc14a3)] michael@0: interface nsIFileInputStream : nsIInputStream michael@0: { michael@0: /** michael@0: * @param file file to read from michael@0: * @param ioFlags file open flags listed in prio.h (see michael@0: * PR_Open documentation) or -1 to open the michael@0: * file in default mode (PR_RDONLY). michael@0: * @param perm file mode bits listed in prio.h or -1 to michael@0: * use the default value (0) michael@0: * @param behaviorFlags flags specifying various behaviors of the class michael@0: * (see enumerations in the class) michael@0: */ michael@0: void init(in nsIFile file, in long ioFlags, in long perm, michael@0: in long behaviorFlags); michael@0: michael@0: /** michael@0: * If this is set, the file will be deleted by the time the stream is michael@0: * closed. It may be removed before the stream is closed if it is possible michael@0: * to delete it and still read from it. michael@0: * michael@0: * If OPEN_ON_READ is defined, and the file was recreated after the first michael@0: * delete, the file will be deleted again when it is closed again. michael@0: */ michael@0: const long DELETE_ON_CLOSE = 1<<1; michael@0: michael@0: /** michael@0: * If this is set, the file will close automatically when the end of the michael@0: * file is reached. michael@0: */ michael@0: const long CLOSE_ON_EOF = 1<<2; michael@0: michael@0: /** michael@0: * If this is set, the file will be reopened whenever we reach the start of michael@0: * the file, either by doing a Seek(0, NS_SEEK_CUR), or by doing a relative michael@0: * seek that happen to reach the beginning of the file. If the file is michael@0: * already open and the seek occurs, it will happen naturally. (The file michael@0: * will only be reopened if it is closed for some reason.) michael@0: */ michael@0: const long REOPEN_ON_REWIND = 1<<3; michael@0: michael@0: /** michael@0: * If this is set, the file will be opened (i.e., a call to michael@0: * PR_Open done) only when we do an actual operation on the stream, michael@0: * or more specifically, when one of the following is called: michael@0: * - Seek michael@0: * - Tell michael@0: * - SetEOF michael@0: * - Available michael@0: * - Read michael@0: * - ReadLine michael@0: * michael@0: * DEFER_OPEN is useful if we use the stream on a background michael@0: * thread, so that the opening and possible |stat|ing of the file michael@0: * happens there as well. michael@0: * michael@0: * @note Using this flag results in the file not being opened michael@0: * during the call to Init. This means that any errors that might michael@0: * happen when this flag is not set would happen during the michael@0: * first read. Also, the file is not locked when Init is called, michael@0: * so it might be deleted before we try to read from it. michael@0: */ michael@0: const long DEFER_OPEN = 1<<4; michael@0: }; michael@0: michael@0: /** michael@0: * An output stream that lets you stream to a file. michael@0: */ michael@0: [scriptable, uuid(e6f68040-c7ec-11d3-8cda-0060b0fc14a3)] michael@0: interface nsIFileOutputStream : nsIOutputStream michael@0: { michael@0: /** michael@0: * @param file file to write to michael@0: * @param ioFlags file open flags listed in prio.h (see michael@0: * PR_Open documentation) or -1 to open the michael@0: * file in default mode (PR_WRONLY | michael@0: * PR_CREATE_FILE | PR_TRUNCATE) michael@0: * @param perm file mode bits listed in prio.h or -1 to michael@0: * use the default permissions (0664) michael@0: * @param behaviorFlags flags specifying various behaviors of the class michael@0: * (currently none supported) michael@0: */ michael@0: void init(in nsIFile file, in long ioFlags, in long perm, michael@0: in long behaviorFlags); michael@0: michael@0: /** michael@0: * See the same constant in nsIFileInputStream. The deferred open will michael@0: * be performed when one of the following is called: michael@0: * - Seek michael@0: * - Tell michael@0: * - SetEOF michael@0: * - Write michael@0: * - Flush michael@0: * michael@0: * @note Using this flag results in the file not being opened michael@0: * during the call to Init. This means that any errors that might michael@0: * happen when this flag is not set would happen during the michael@0: * first write, and if the file is to be created, then it will not michael@0: * appear on the disk until the first write. michael@0: */ michael@0: const long DEFER_OPEN = 1<<0; michael@0: }; michael@0: michael@0: /** michael@0: * An input stream that allows you to read from a slice of a file. michael@0: */ michael@0: [scriptable, uuid(3ce03a2f-97f7-4375-b6bb-1788a60cad3b)] michael@0: interface nsIPartialFileInputStream : nsISupports michael@0: { michael@0: /** michael@0: * Initialize with a file and new start/end positions. Both start and michael@0: * start+length must be smaller than the size of the file. Not doing so michael@0: * will lead to undefined behavior. michael@0: * You must initialize the stream, and only initialize it once, before it michael@0: * can be used. michael@0: * michael@0: * @param file file to read from michael@0: * @param start start offset of slice to read. Must be smaller michael@0: * than the size of the file. michael@0: * @param length length of slice to read. Must be small enough that michael@0: * start+length is smaller than the size of the file. michael@0: * @param ioFlags file open flags listed in prio.h (see michael@0: * PR_Open documentation) or -1 to open the michael@0: * file in default mode (PR_RDONLY). michael@0: * @param perm file mode bits listed in prio.h or -1 to michael@0: * use the default value (0) michael@0: * @param behaviorFlags flags specifying various behaviors of the class michael@0: * (see enumerations in nsIFileInputStream) michael@0: */ michael@0: void init(in nsIFile file, in unsigned long long start, michael@0: in unsigned long long length, michael@0: in long ioFlags, in long perm, in long behaviorFlags); michael@0: }; michael@0: michael@0: /** michael@0: * A stream that allows you to read from a file or stream to a file. michael@0: */ michael@0: [scriptable, uuid(82cf605a-8393-4550-83ab-43cd5578e006)] michael@0: interface nsIFileStream : nsISupports michael@0: { michael@0: /** michael@0: * @param file file to read from or stream to michael@0: * @param ioFlags file open flags listed in prio.h (see michael@0: * PR_Open documentation) or -1 to open the michael@0: * file in default mode (PR_RDWR). michael@0: * @param perm file mode bits listed in prio.h or -1 to michael@0: * use the default value (0) michael@0: * @param behaviorFlags flags specifying various behaviors of the class michael@0: * (see enumerations in the class) michael@0: */ michael@0: void init(in nsIFile file, in long ioFlags, in long perm, michael@0: in long behaviorFlags); michael@0: michael@0: /** michael@0: * See the same constant in nsIFileInputStream. The deferred open will michael@0: * be performed when one of the following is called: michael@0: * - Seek michael@0: * - Tell michael@0: * - SetEOF michael@0: * - Available michael@0: * - Read michael@0: * - Flush michael@0: * - Write michael@0: * - GetSize michael@0: * - GetLastModified michael@0: * michael@0: * @note Using this flag results in the file not being opened michael@0: * during the call to Init. This means that any errors that might michael@0: * happen when this flag is not set would happen during the michael@0: * first read or write. The file is not locked when Init is called, michael@0: * so it might be deleted before we try to read from it and if the michael@0: * file is to be created, then it will not appear on the disk until michael@0: * the first write. michael@0: */ michael@0: const long DEFER_OPEN = 1<<0; michael@0: }; michael@0: michael@0: /** michael@0: * An interface that allows you to get some metadata like file size and michael@0: * file last modified time. michael@0: */ michael@0: [scriptable, uuid(07f679e4-9601-4bd1-b510-cd3852edb881)] michael@0: interface nsIFileMetadata : nsISupports michael@0: { michael@0: /** michael@0: * File size in bytes; michael@0: */ michael@0: readonly attribute long long size; michael@0: michael@0: /** michael@0: * File last modified time in milliseconds from midnight (00:00:00), michael@0: * January 1, 1970 Greenwich Mean Time (GMT). michael@0: */ michael@0: readonly attribute long long lastModified; michael@0: };