https://github.com/leonklingele/securetemp
Secure temporary directories and files in Go (ram disk, tmpfs)
https://github.com/leonklingele/securetemp
ramdisk security temporary-directories temporary-files tmpfile tmpfs
Last synced: 11 months ago
JSON representation
Secure temporary directories and files in Go (ram disk, tmpfs)
- Host: GitHub
- URL: https://github.com/leonklingele/securetemp
- Owner: leonklingele
- License: agpl-3.0
- Created: 2017-08-10T09:12:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-01-18T09:31:20.000Z (about 5 years ago)
- Last Synced: 2025-03-26T02:23:46.183Z (about 1 year ago)
- Topics: ramdisk, security, temporary-directories, temporary-files, tmpfile, tmpfs
- Language: Go
- Homepage:
- Size: 1.03 MB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Secure temporary directories and files in Go
[](https://travis-ci.org/leonklingele/securetemp)
This CLI app and library can be used to create temporary directories and files inside RAM.
This is useful if you temporarily need a file to store sensitive data in.
## tl;dr
```sh
# Install library
go get -u github.com/leonklingele/securetemp
# Install library + CLI app ("securetemp")
go get -u github.com/leonklingele/securetemp/...
securetemp -h
```
```go
// Create a temporary file inside a RAM disk which is securetemp.DefaultSize big
tmpFile, cleanupFunc, err := securetemp.TempFile(securetemp.DefaultSize)
if err != nil {
// TODO: Properly handle error
log.Fatal(err)
}
// `tmpFile` is an *os.File
if _, err := tmpFile.WriteString("Hello, World!"); err != nil {
// TODO: Properly handle error
log.Fatal(err)
}
// Call the cleanup func as soon as you no longer need the file.
// The file is deleted and the RAM is freed again.
// The cleanup function also calls `tmpFile.Close()` for you.
cleanupFunc()
```
```go
// Create a temporary directory inside a RAM disk which is 20MB big
tmpDir, cleanupFunc, err := securetemp.TempDir(20 * securetemp.SizeMB)
if err != nil {
// TODO: Properly handle error
log.Fatal(err)
}
// Create one / multiple file/s inside `tmpDir`
file, err := os.Create(path.Join(tmpDir, "myfile.txt"))
if err != nil {
// TODO: Properly handle error
log.Fatal(err)
}
defer file.Close()
// Do something with `file`
if _, err := file.WriteString("Hello, World!"); err != nil {
// TODO: Properly handle error
log.Fatal(err)
}
file.Close()
// Call the cleanup func as soon as you no longer need the directory.
// The directory is deleted and the RAM is freed again.
// Make sure to close every file inside `tmpDir` before.
cleanupFunc()
```
## Idea
This project was inspired by [pass](https://www.passwordstore.org/)