-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempfile.go
43 lines (37 loc) · 905 Bytes
/
tempfile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
GoLang code created by Jirawat Harnsiriwatanakit https://github.com/kazekim
*/
package pdfinject
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"log"
)
type TempFile struct {
path string
}
// NewTempFile Create a FDF Generator.
func NewTempFile(dir, prefix string) (*TempFile, error) {
tmpDir, err := ioutil.TempDir(dir, prefix)
if err != nil {
return nil, fmt.Errorf("failed to create temporary directory: %v", err)
}
return &TempFile{
tmpDir,
}, nil
}
// GetTempOutputFilePath Get a temporary output file path
func (t *TempFile) GetTempOutputFilePath() string {
file := filepath.Clean(t.path + "/output.pdf")
return file
}
// Remove delete temp directory when finish process
func (t *TempFile) Remove() {
errD := os.RemoveAll(t.path)
// Log the error only.
if errD != nil {
log.Printf("pdfinject: failed to remove temporary directory '%s' again: %v", t.path, errD)
}
}