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)
| 286 | // Errors from the minifier are returned by Close on the writer. |
| 287 | // The writer must be closed explicitly. |
| 288 | func (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. |