Dec 2007: Initial release
May 2009: Inherit File
Daniel Keep
Thanks to John Reimer for helping test this module under
Linux.
- class TempFile : File ¶
-
The TempFile class aims to provide a safe way of creating and destroying
temporary files. The TempFile class will automatically close temporary
files when the object is destroyed, so it is recommended that you make
appropriate use of scoped destruction.
Temporary files can be created with one of several styles, much like normal
Files. TempFile styles have the following properties:
- Transience: this determines whether the file should be destroyed
as soon as it is closed (transient,) or continue to persist even after the
application has terminated (permanent.)
Eventually, this will be expanded to give you greater control over the
temporary file's properties.
For the typical use-case (creating a file to temporarily store data too
large to fit into memory,) the following is sufficient:
1
2
3
4
5
6
|
{
scope temp = new TempFile;
// Use temp as a normal conduit; it will be automatically closed when
// it goes out of scope.
}
|
It is recommended that you do not use files created by this class to
store sensitive information. There are several known issues with the
current implementation that could allow an attacker to access the contents
of these temporary files.
Detail security properties and guarantees.
- enum Transience : ubyte ¶
-
This enumeration is used to control whether the temporary file should
persist after the TempFile object has been destroyed.
- Transient ¶
-
The temporary file should be destroyed along with the owner object.
- Permanent ¶
-
The temporary file should persist after the object has been
destroyed.
- struct TempStyle ¶
-
This structure is used to determine how the temporary files should be
opened and used.
- Transience transience ¶
- ubyte attempts ¶
- TempStyle Transient [gshared, static, const] ¶
-
TempStyle for creating a transient temporary file that only the current
user can access.
- TempStyle Permanent [gshared, static, const] ¶
-
TempStyle for creating a permanent temporary file that only the current
user can access.
- this(TempStyle style = init) ¶
- this(const(char)[] prefix, TempStyle style = init) ¶
- TempStyle tempStyle() ¶
-
Indicates the style that this TempFile was created with.
- const(char)[] tempPath() [public, static] ¶
-
Returns the path to the directory where temporary files will be
created. The returned path is safe to mutate.