Git Product home page Git Product logo

securetemp's Introduction

Secure temporary directories and files in Go

Build Status

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

# Install library
go get -u github.com/leonklingele/securetemp

# Install library + CLI app ("securetemp")
go get -u github.com/leonklingele/securetemp/...
securetemp -h
// 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()
// 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

securetemp's People

Contributors

leonklingele avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

x-clone wahello

securetemp's Issues

Does not seem to build on Windows

Hello,

I wanted to test out Securetemp on Windows and it does not seem to build.

C:\goprojects\src\securetemp>go get -u github.com/leonklingele/securetemp
# github.com/leonklingele/securetemp
..\..\pkg\mod\github.com\leonklingele\[email protected]+incompatible\securetemp_unix.go:35:5: undefined: unix.Access
..\..\pkg\mod\github.com\leonklingele\[email protected]+incompatible\securetemp_unix.go:35:29: undefined: unix.W_OK
..\..\pkg\mod\github.com\leonklingele\[email protected]+incompatible\securetemp_unix.go:35:50: undefined: unix.Access
..\..\pkg\mod\github.com\leonklingele\[email protected]+incompatible\securetemp_unix.go:35:74: undefined: unix.X_OK
..\..\pkg\mod\github.com\leonklingele\[email protected]+incompatible\securetemp_windows.go:7:6: createRAMDisk redeclared in this block
        previous declaration at ..\..\pkg\mod\github.com\leonklingele\[email protected]+incompatible\securetemp_unix.go:21:52

Then

C:\goprojects\src\securetemp>go build cmd\securetemp\main.go
cmd\securetemp\main.go:10:2: no required module provides package github.com/leonklingele/securetemp: working directory is not part of a module

Using

C:\goprojects\src\securetemp>go version
go version go1.16 windows/amd64

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.