This enumeration is used to control whether the temporary file should persist after the TempFile object has been destroyed.
Indicates the style that this TempFile was created with.
Returns the path to the directory where temporary files will be created. The returned path is safe to mutate.
Returns the path to the directory where temporary files will be created. The returned path is safe to mutate.
TempStyle for creating a permanent temporary file that only the current user can access.
TempStyle for creating a transient temporary file that only the current user can access.
This structure is used to determine how the temporary files should be opened and used.
Fits into 32 bits ...
Read an existing file.
Read an existing file.
Write on an existing file. Do not create.
Write on a clean file. Create if necessary.
Write at the end of the file.
Read and write an existing file.
Read & write on a clean file. Create if necessary.
Read and Write. Use existing file if present.
Return the Style used for this file.
Return the path used by this file.
Convenience function to return the content of a file. Returns a slice of the provided output buffer, where that has sufficient capacity, and allocates from the heap where the file content is larger.
Convenience function to set file content and length to reflect the given array.
Convenience function to append content to a file.
Low level open for sub-classes that need to apply specific attributes.
Open a file with the provided style.
Set the file size to be that of the current seek position. The file must be writable for this to succeed.
Set the file size to be the specified length. The file must be writable for this to succeed.
Set the file seek position to the specified offset from the given anchor.
Return the current file position.
Return the total length of this file.
Instructs the OS to flush it's internal buffers to the disk device.
Low level open for sub-classes that need to apply specific attributes.
Open a file with the provided style.
Set the file size to be that of the current seek position. The file must be writable for this to succeed.
Set the file size to be the specified length. The file must be writable for this to succeed.
Set the file seek position to the specified offset from the given anchor.
Return the current file position.
Return the total length of this file.
Instructs the OS to flush it's internal buffers to the disk device.
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:
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:
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.