MCPcopy
hub / github.com/tdewolff/minify / Writer

Method Writer

minify.go:288–300  ·  view source on GitHub ↗

Writer wraps a Writer interface and minifies the stream. Errors from the minifier are returned by Close on the writer. The writer must be closed explicitly.

(mediatype string, w io.Writer)

Source from the content-addressed store, hash-verified

286// Errors from the minifier are returned by Close on the writer.
287// The writer must be closed explicitly.
288func (m *M) Writer(mediatype string, w io.Writer) io.WriteCloser {
289 pr, pw := io.Pipe()
290 z := &writer{pw, sync.WaitGroup{}, false, nil}
291 z.wg.Add(1)
292 go func() {
293 defer z.wg.Done()
294 defer pr.Close()
295 if err := m.Minify(mediatype, w, pr); err != nil {
296 z.err = err
297 }
298 }()
299 return z
300}
301
302// responseWriter wraps an http.ResponseWriter and makes sure that errors from the minifier are passed down through Close (can be blocking).
303// All writes to the response writer are intercepted and minified on the fly.

Callers 3

TestWriterFunction · 0.80
ExampleM_WriterFunction · 0.80
ExampleMinify_writerFunction · 0.80

Calls 3

MinifyMethod · 0.95
AddMethod · 0.80
CloseMethod · 0.45

Tested by 3

TestWriterFunction · 0.64
ExampleM_WriterFunction · 0.64
ExampleMinify_writerFunction · 0.64