License:
BSD style: see license.txt
Version:
Initial release: December 2007
Authors:
Daniel Keep
credits:
Thanks to John Reimer for helping test this module under
Linux.
- class
TempFile
: tango.io.device.DeviceConduit.DeviceConduit, tango.io.model.IConduit.IConduit.Seek;
- 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
FileConduits.
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:
{
scope temp = new TempFile;
// Use temp as a normal conduit; it will be automatically closed when
// it goes out of scope.
}
Important:
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.
Todo: Detail security properties and guarantees.
- enum
Transience
;
- 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
Style
;
- This structure is used to determine how the temporary files should be
opened and used.
- Transience
transience
;
- int
attempts
;
- static const Style
Transient
;
- Style for creating a transient temporary file that only the current
user can access.
- static const Style
Permanent
;
- Style for creating a permanent temporary file that only the current
user can access.
- this(Style style = (Style ).init);
- this(char[] prefix, Style style = (Style ).init);
- this(FilePath prefix, Style style = (Style ).init);
- Deprecated:
please use char[] version instead
- char[]
path
();
- Returns the
path
of the temporary file. Please note that depending
on your platform, the returned
path
may or may not actually exist if
you specified a transient file.
- Style
style
();
- Indicates the
style
that this TempFile was created with.
- long
position
();
- Returns the current cursor
position
within the file.
- long
length
();
- Returns the total
length
, in bytes, of the temporary file.
|