MCPcopy Create free account
hub / github.com/containerd/nerdctl / SaveToWriter

Method SaveToWriter

mod/tigron/test/data.go:120–153  ·  view source on GitHub ↗
(writer func(file io.Writer) error, key ...string)

Source from the content-addressed store, hash-verified

118}
119
120func (tp *temp) SaveToWriter(writer func(file io.Writer) error, key ...string) string {
121 tp.t.Helper()
122
123 tp.Dir(key[:len(key)-1]...)
124
125 pth := filepath.Join(append([]string{tp.tempDir}, key...)...)
126 silentT := assertive.WithSilentSuccess(tp.t)
127
128 //nolint:gosec // it is fine
129 file, err := os.OpenFile(pth, os.O_CREATE|os.O_WRONLY, FilePermissionsDefault)
130 assertive.ErrorIsNil(
131 silentT,
132 err,
133 fmt.Sprintf("Opening file %q must succeed", pth),
134 )
135
136 defer func() {
137 err = file.Close()
138 assertive.ErrorIsNil(
139 silentT,
140 err,
141 fmt.Sprintf("Closing file %q must succeed", pth),
142 )
143 }()
144
145 err = writer(file)
146 assertive.ErrorIsNil(
147 silentT,
148 err,
149 fmt.Sprintf("Filewriter failed while attempting to write to %q", pth),
150 )
151
152 return pth
153}
154
155func (tp *temp) Dir(key ...string) string {
156 tp.t.Helper()

Callers

nothing calls this directly

Calls 3

DirMethod · 0.95
HelperMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected