sync: Implement writable importer
This commit is contained in:
parent
8ed9415c68
commit
aab66bf612
4 changed files with 55 additions and 0 deletions
|
@ -53,6 +53,12 @@ type ForgeLinkedImporter interface {
|
|||
GetExerciceLink(e *fic.Exercice) (*url.URL, error)
|
||||
}
|
||||
|
||||
// WritableImporter abstracts importer that we can also write on
|
||||
type WritableImporter interface {
|
||||
// writeFile write the given buffer to the file at the given location.
|
||||
writeFile(filename string, reader io.Reader) error
|
||||
}
|
||||
|
||||
// GlobalImporter stores the main importer instance to use for global imports.
|
||||
var GlobalImporter Importer
|
||||
|
||||
|
@ -189,3 +195,12 @@ func ImportFile(i Importer, URI string, next func(string, string) (interface{},
|
|||
|
||||
return next(dest, URI)
|
||||
}
|
||||
|
||||
// WriteFileContent save the given content to the given text file.
|
||||
func WriteFileContent(i Importer, URI string, content []byte) error {
|
||||
if wi, ok := i.(WritableImporter); ok {
|
||||
return wi.writeFile(URI, bytes.NewReader(content))
|
||||
} else {
|
||||
return fmt.Errorf("%t is not capable of writing", i)
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue