Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
.github/workflows/ | H | 19-May-2021 | - | |||
examples/tmpfile-cwd/ | H | 19-May-2021 | - | |||
.golangci.yml | H A D | 19-May-2021 | 668 | |||
LICENSE | H A D | 19-May-2021 | 1 KiB | |||
LICENSE.golang | H A D | 19-May-2021 | 1.4 KiB | |||
README.md | H A D | 19-May-2021 | 1.8 KiB | |||
doc.go | H A D | 19-May-2021 | 501 | |||
doc_test.go | H A D | 19-May-2021 | 494 | |||
go.mod | H A D | 19-May-2021 | 106 | |||
go.sum | H A D | 19-May-2021 | 207 | |||
tmpfile.go | H A D | 19-May-2021 | 730 | |||
tmpfile_notexists_test.go | H A D | 19-May-2021 | 271 | |||
tmpfile_notexists_windows_test.go | H A D | 19-May-2021 | 454 | |||
tmpfile_test.go | H A D | 19-May-2021 | 5 KiB | |||
tmpfile_windows.go | H A D | 19-May-2021 | 2.4 KiB |
README.md
1[![Documentation][godoc.badge]][godoc] 2[![Test Status][workflow.tests.badge]][workflow.tests] 3 4# Cross Platform Temporary Files 5 6This library attempts to bridge the gap between the what is provided in 7[ioutil.TempFile][ioutil.tempfile] and the best practice of ensuring temporary 8files are ***always*** deleted when the application exits. 9 10The normal way to do this on a POSIX system is to use the behavior of 11[unlink][posix.unlink] to immediately remove the directory entry for the 12temporary file. The OS then ensures that when all open file handles on the file 13are close that the file resources are removed. Unfortunately, despite Go having 14[os.Remove][os.remove] this does not work on Windows because on Windows it is 15necessary to open the files with special flags 16([FILE_SHARE_DELETE][windows.flags.share], 17[FILE_FLAG_DELETE_ON_CLOSE][windows.flags.on_close]) to enable removing a file 18that is open (and ioutil does not do this). 19 20Example usage: 21 22```go 23package main 24 25import "github.com/calebcase/tmpfile" 26 27func main() { 28 f, err := tmpfile.New("", "example-*") 29 if err != nil { 30 panic(err) 31 } 32 defer f.Close() 33 34 f.WriteString("Example Data") 35} 36``` 37 38--- 39 40[godoc.badge]: https://godoc.org/github.com/calebcase/tmpfile?status.svg 41[godoc]: https://godoc.org/github.com/calebcase/tmpfile 42[ioutil.tempfile]: https://golang.org/pkg/io/ioutil/#TempFile 43[os.remove]: https://golang.org/pkg/os/#Remove 44[posix.unlink]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html 45[windows.flags.on_close]: https://github.com/golang/sys/blob/master/windows/types_windows.go#L108 46[windows.flags.share]: https://github.com/golang/sys/blob/master/windows/types_windows.go#L71 47[workflow.tests.badge]: https://github.com/calebcase/tmpfile/workflows/tests/badge.svg 48[workflow.tests]: https://github.com/calebcase/tmpfile/actions?query=workflow%3Atests 49