// srcFile could be a single file or a directory
srcFile could be a single file or a directory
// srcFile could be a single file or a directory
func (d *Docx) Zip(destZip string) error {
	srcFile := d.FilePath + string(filepath.Separator)
	zipfile, err := os.Create(destZip)
	if err != nil {
		return err
	}
	defer zipfile.Close()
	archive := zip.NewWriter(zipfile)
	defer archive.Close()
	filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if info.IsDir() {
			return nil
		}
		t, err := os.Open(path)
		defer t.Close()
		name := strings.TrimPrefix(path, srcFile)
		var flag = true
		if strings.HasSuffix(name, "embeddings") || strings.HasSuffix(name, "media") {
			if ok, err := d.canSave(info.Name()); !ok || err != nil {
				flag = false
			}
		}
		if flag {
			tf, err := archive.Create(name)
			if err != nil {
				return err
			}
			data, err := ioutil.ReadAll(t)
			if err != nil {
				return err
			}
			_, err = tf.Write(data)
			if err != nil {
				return err
			}
		}
		return err
	})
	return err
}
func ( d * Docx ) Zip ( destZip string ) error { srcFile := d . FilePath + string ( filepath . Separator ) zipfile , err := os . Create ( destZip ) if err != nil { return err } defer zipfile . Close ( ) archive := zip . NewWriter ( zipfile ) defer archive . Close ( ) filepath . Walk ( srcFile , func ( path string , info os . FileInfo , err error ) error { if err != nil { return err } if info . IsDir ( ) { return nil } t , err := os . Open ( path ) defer t . Close ( ) name := strings . TrimPrefix ( path , srcFile ) var flag = true if strings . HasSuffix ( name , " " ) || strings . HasSuffix ( name , " " ) { if ok , err := d . canSave ( info . Name ( ) ) ; ! ok || err != nil { flag = false } } if flag { tf , err := archive . Create ( name ) if err != nil { return err } data , err := ioutil . ReadAll ( t ) if err != nil { return err } _ , err = tf . Write ( data ) if err != nil { return err } } return err } ) return err }
srcFile could be a single file or a directory
srcFile could be a single file or a directory