MCPcopy Index your code
hub / github.com/foxcpp/maddy / BufferInFile

Function BufferInFile

framework/buffer/file.go:65–85  ·  view source on GitHub ↗

BufferInFile is a convenience function which creates FileBuffer with underlying file created in the specified directory with the random name.

(r io.Reader, dir string)

Source from the content-addressed store, hash-verified

63// BufferInFile is a convenience function which creates FileBuffer with underlying
64// file created in the specified directory with the random name.
65func BufferInFile(r io.Reader, dir string) (Buffer, error) {
66 // It is assumed that PRNG is initialized somewhere during program startup.
67 nameBytes := make([]byte, 32)
68 _, err := rand.Read(nameBytes)
69 if err != nil {
70 return nil, fmt.Errorf("buffer: failed to generate randomness for file name: %v", err)
71 }
72 path := filepath.Join(dir, hex.EncodeToString(nameBytes))
73 f, err := os.Create(path)
74 if err != nil {
75 return nil, fmt.Errorf("buffer: failed to create file: %v", err)
76 }
77 if _, err = io.Copy(f, r); err != nil {
78 return nil, fmt.Errorf("buffer: failed to write file: %v", err)
79 }
80 if err := f.Close(); err != nil {
81 return nil, fmt.Errorf("buffer: failed to close file: %v", err)
82 }
83
84 return FileBuffer{Path: path}, nil
85}

Callers 2

autoBufferModeFunction · 0.92
bufferModeDirectiveFunction · 0.92

Calls 4

CopyMethod · 0.80
CreateMethod · 0.65
CloseMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected