Created
February 21, 2016 07:41
-
-
Save sgykfjsm/299c7b3295dff884c8ab to your computer and use it in GitHub Desktop.
tdewolff/minify sample using reader and writer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems tdewolff/minify doesn't work with svg file as expected.