Documentation ¶
Overview ¶
Package tempura provides temporary files creation and manipulation helpers for the purposes of enhancing tests involving files creation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
Create a new temporary file in the directory dir with a name beginning with prefix, writes the provided data into it and returns it's path.
If dir is the empty string, TempFile uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempFile simultaneously will not choose the same file. It is the caller's responsibility to remove the file when no longer needed.
Types ¶
type TempFile ¶
TempFile represents an open temporary file descriptor
func FromBytes ¶
FromBytes creates a new temporary file in the directory dir with a name beginning with prefix, opens the file for reading and writing, writes the provided data into it and returns seeks the underlying file object to 0.
If dir is the empty string, TempFile uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempFile simultaneously will not choose the same file. The caller can use f.Name() to find the pathname of the file. It is the caller's responsibility to remove the file when no longer needed.
Example ¶
var tmp *TempFile var err error // Creates a temporary file in /tmp dir, prefixed with "test_" // and containing three bytes "a", "b", "c" tmp, err = FromBytes("/tmp", "test_", []byte{'a', 'b', 'c'}) if err != nil { // Handle err } defer tmp.Close() defer os.Remove(tmp.Name()) // The tmp file descriptor is seeked to 0 and ready to be read/written data, err := tmp.Read(make([]byte, 3)) if err != nil { // Handle error } fmt.Println(string(data))
Output: "abc"