(optional) File open flags. Can be undefined. * @returns nsIFileOutputStream to write to. * Note: The stream is initialized with the DEFER_OPEN behavior flag. * See nsIFileOutputStream. */ openSafeFileOutputStream: function FileUtils_openSafeFileOutputStream( file, modeFlags ) { var fos = Cc[ "@mozilla.org/network/safe-file-output-stream;1" ].createInstance(Ci.nsIFileOutputStream); return this._initFileOutputStream(fos, file, modeFlags); }, _initFileOutputStream: function FileUtils__initFileOutputStream( fos, file, modeFlags ) { if (modeFlags === undefined) { modeFlags = this.MODE_WRONLY | this.MODE_CREATE | this.MODE_TRUNCATE; } fos.init(file, modeFlags, this.PERMS_FILE, fos.DEFER_OPEN); return fos; }, /** * Closes an atomic file output stream. * * @param stream * The stream to close. */ closeAtomicFileOutputStream: function FileUtils_closeAtomicFileOutputStream( stream ) { if (stream instanceof Ci.nsISafeOutputStream) { try { stream.finish(); return; } catch (e) {} } stream.close(); }, /** * Closes a safe file output stream. * * @param stream * The stream to close. */ closeSafeFileOutputStream: function FileUtils_closeSafeFileOutputStream( stream ) { if (stream instanceof Ci.nsISafeOutputStream) { try { stream.finish(); return; } catch (e) {} } stream.close(); }, File: Components.Constructor( "@mozilla.org/file/local;1", Ci.nsIFile, "initWithPath" ), }; PK