MCPcopy Create free account
hub / github.com/bwplotka/mimic / Add

Method Add

files.go:31–48  ·  view source on GitHub ↗

Add adds a file to the file pool at the current path. The file is identified by filename. Content of the file is passed via an io.Reader. If the file with the given name has already been added at this path the code will `panic`. NOTE: See mimic/encoding for different marshallers to use as io.Reader

(fileName string, r io.Reader)

Source from the content-addressed store, hash-verified

29// If the file with the given name has already been added at this path the code will `panic`.
30// NOTE: See mimic/encoding for different marshallers to use as io.Reader.
31func (f *FilePool) Add(fileName string, r io.Reader) {
32 if filepath.Base(fileName) != fileName {
33 Panicf("")
34 }
35
36 b, err := ioutil.ReadAll(r)
37 if err != nil {
38 Panicf("failed to output: %s", err)
39 }
40
41 output := filepath.Join(append(f.path, fileName)...)
42
43 // Check whether we have already written something into this file.
44 if _, ok := f.m[output]; ok {
45 Panicf("filename clash: %s", output)
46 }
47 f.m[output] = string(b)
48}
49
50func (f *FilePool) write(outputDir string) {
51 for file, contents := range f.m {

Callers 3

genRRTestPrometheusFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 1

PanicfFunction · 0.85

Tested by

no test coverage detected