admin: new function to retrieve file content
This commit is contained in:
parent
ae7e1ede14
commit
a033f81f5f
1 changed files with 12 additions and 0 deletions
|
@ -2,9 +2,11 @@ package sync
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/base32"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
@ -58,6 +60,16 @@ func getFile(i Importer, URI string, writer *bufio.Writer) error {
|
|||
return errors.New(fmt.Sprintf("%q: no such file or directory", i.toURL(URI)))
|
||||
}
|
||||
|
||||
func getFileContent(i Importer, URI string) (string, error) {
|
||||
cnt := bytes.Buffer{}
|
||||
|
||||
if err := getFile(i, URI, bufio.NewWriter(io.Writer(&cnt))); err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
return strings.TrimSpace(cnt.String()), nil
|
||||
}
|
||||
}
|
||||
|
||||
func ImportFile(URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
|
||||
hash := blake2b.Sum512([]byte(URI))
|
||||
dest := path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:])), path.Base(URI))
|
||||
|
|
Reference in a new issue