Write docs!

This commit is contained in:
nemunaire 2018-03-09 19:07:08 +01:00
parent c460bb7bf5
commit bcc598ebd5
37 changed files with 478 additions and 188 deletions

View file

@ -16,10 +16,15 @@ import (
"golang.org/x/crypto/blake2b"
)
// Importer are abstract methods required to import challenges.
type Importer interface {
// Kind returns information about the Importer, for human interrest.
Kind() string
// exists checks if the given location exists from the Importer point of view.
exists(filename string) bool
// toURL gets the full path/URL to the given file, the Importer will look internaly (used for debuging purpose).
toURL(filename string) string
// importFile imports the file at the given URI
importFile(URI string, next func(string, string) (interface{}, error)) (interface{}, error)
getFile(filename string, writer *bufio.Writer) error
listDir(filename string) ([]string, error)
@ -62,6 +67,7 @@ func getFile(i Importer, URI string, writer *bufio.Writer) error {
return errors.New(fmt.Sprintf("%q: no such file or directory", URI))
}
// getFileContent
func getFileContent(i Importer, URI string) (string, error) {
cnt := bytes.Buffer{}
@ -72,11 +78,16 @@ func getFileContent(i Importer, URI string) (string, error) {
}
}
// getDestinationFilePath generates the destination path, from the URI.
// This function permits to obfusce to player the original URI.
// Theoricaly, changing the import method doesn't change destination URI.
func getDestinationFilePath(URI string) string {
hash := blake2b.Sum512([]byte(URI))
return path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:])), path.Base(URI))
}
// ImportFile imports the file at the given URI, using helpers of the given Importer.
// After import, next is called with relative path where the file has been saved and the original URI.
func ImportFile(i Importer, URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
dest := getDestinationFilePath(URI)