admin: new function to retrieve file content

This commit is contained in:
nemunaire 2017-12-09 01:20:30 +01:00
parent ae7e1ede14
commit a033f81f5f

View file

@ -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))