package reader import ( "archive/zip" "bytes" "io/ioutil" "os" ) const SketchPreviewPath = "previews/preview.png" type Sketch struct { } func (s *Sketch)ReadPreviewFromData(data []byte)([]byte, error){ readAt := bytes.NewReader(data) ziper, err := zip.NewReader(readAt, int64(len(data))) if err != nil { return nil, err } pf, err := ziper.Open(SketchPreviewPath) if err != nil { return nil, err } defer pf.Close() res, err := ioutil.ReadAll(pf) return res, err } func (s *Sketch)ReadPreview(name string)([]byte, error){ ziper, err := zip.OpenReader(name) if err != nil { return nil, err } pf, err := ziper.Open(SketchPreviewPath) if err != nil { return nil, err } defer pf.Close() res, err := ioutil.ReadAll(pf) return res, err } func (s *Sketch)SavePreview(file string)error{ data, err := s.ReadPreview(file) if err != nil { return err } return os.WriteFile(file+".png", data, os.ModePerm) }