Skip to content

Instantly share code, notes, and snippets.

@sgykfjsm
Created February 21, 2016 07:41
Show Gist options
  • Save sgykfjsm/299c7b3295dff884c8ab to your computer and use it in GitHub Desktop.
Save sgykfjsm/299c7b3295dff884c8ab to your computer and use it in GitHub Desktop.
tdewolff/minify sample using reader and writer
package main
import (
"bufio"
"log"
"os"
"github.com/tdewolff/minify"
"github.com/tdewolff/minify/svg"
)
func minifySVG(svgFile string) error {
mediaType := "image/svg+xml"
m := minify.New()
m.AddFunc(mediaType, svg.Minify)
f, err := os.Open(svgFile)
if err != nil {
return err
}
defer f.Close()
f2, err := os.Create("/tmp/dest.svg")
if err != nil {
return err
}
defer f2.Close()
w := bufio.NewWriter(f2)
r := bufio.NewReader(f)
if err := m.Minify(mediaType, w, r); err != nil {
return err
}
return nil
}
func main() {
err := minifySVG("/tmp/org.svg")
log.Println(err)
}
@sgykfjsm
Copy link
Author

It seems tdewolff/minify doesn't work with svg file as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment