mirror of https://github.com/Xhofe/alist
chore: create temp file util
parent
6cdd85283b
commit
066ddd3e09
|
@ -1 +1,6 @@
|
||||||
package message
|
package message
|
||||||
|
|
||||||
|
type Messager interface {
|
||||||
|
Send(string, interface{}) error
|
||||||
|
Receive(string) (string, error)
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/sirupsen/logrus"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/conf"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Exists determine whether the file exists
|
// Exists determine whether the file exists
|
||||||
|
@ -28,3 +32,20 @@ func CreatNestedFile(path string) (*os.File, error) {
|
||||||
}
|
}
|
||||||
return os.Create(path)
|
return os.Create(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateTempFile create temp file from io.ReadCloser, and seek to 0
|
||||||
|
func CreateTempFile(r io.ReadCloser) (*os.File, error) {
|
||||||
|
f, err := ioutil.TempFile(conf.Conf.TempDir, "file-*")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = io.Copy(f, r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = f.Seek(0, io.SeekStart)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue