-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathout.go
More file actions
40 lines (36 loc) · 727 Bytes
/
out.go
File metadata and controls
40 lines (36 loc) · 727 Bytes
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
package main
import (
"fmt"
"github.com/ConvertAPI/convertapi-go"
"io"
"os"
"strings"
"sync/atomic"
)
var outCnt uintptr = 0
func output(file *convertapi.ResFile, dst string) {
dst = strings.TrimSpace(dst)
if strings.EqualFold(dst, "stdout") {
fd := outIdx()
if fd == 2 {
fd = outIdx()
} // Skipping stderr
out := os.NewFile(fd, file.FileName)
io.Copy(out, file)
file.Delete()
} else if strings.HasPrefix(dst, "@") {
dst = strings.TrimPrefix(dst, "@")
paths := strings.Split(dst, ";")
i := int(outIdx())
if len(paths) < i {
i = len(paths)
}
file.ToPath(paths[i-1])
file.Delete()
} else {
fmt.Println(file.Url)
}
}
func outIdx() uintptr {
return atomic.AddUintptr(&outCnt, 1)
}