Merge "Add support for gzipping html output."
This commit is contained in:
@@ -16,6 +16,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
@@ -55,7 +56,8 @@ func init() {
|
|||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprintf(os.Stderr, `Usage: %s {options} file.meta_lic {file.meta_lic...}
|
fmt.Fprintf(os.Stderr, `Usage: %s {options} file.meta_lic {file.meta_lic...}
|
||||||
|
|
||||||
Outputs an html NOTICE.html file.
|
Outputs an html NOTICE.html or gzipped NOTICE.html.gz file if the -o filename
|
||||||
|
ends with ".gz".
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
`, filepath.Base(os.Args[0]))
|
`, filepath.Base(os.Args[0]))
|
||||||
@@ -94,9 +96,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ofile io.Writer
|
var ofile io.Writer
|
||||||
|
var closer io.Closer
|
||||||
ofile = os.Stdout
|
ofile = os.Stdout
|
||||||
|
var obuf *bytes.Buffer
|
||||||
if *outputFile != "-" {
|
if *outputFile != "-" {
|
||||||
ofile = &bytes.Buffer{}
|
obuf = &bytes.Buffer{}
|
||||||
|
ofile = obuf
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(*outputFile, ".gz") {
|
||||||
|
ofile, _ = gzip.NewWriterLevel(obuf, gzip.BestCompression)
|
||||||
|
closer = ofile.(io.Closer)
|
||||||
}
|
}
|
||||||
|
|
||||||
var deps []string
|
var deps []string
|
||||||
@@ -111,8 +120,12 @@ func main() {
|
|||||||
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
|
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
if closer != nil {
|
||||||
|
closer.Close()
|
||||||
|
}
|
||||||
|
|
||||||
if *outputFile != "-" {
|
if *outputFile != "-" {
|
||||||
err := os.WriteFile(*outputFile, ofile.(*bytes.Buffer).Bytes(), 0666)
|
err := os.WriteFile(*outputFile, obuf.Bytes(), 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "could not write output to %q: %s\n", *outputFile, err)
|
fmt.Fprintf(os.Stderr, "could not write output to %q: %s\n", *outputFile, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
Reference in New Issue
Block a user