Exemplo n.º 1
0
func writeFileToZip(zipper *zip.Writer, filename string) error {
	file, err := os.Open(filename)

	if err != nil {
		return err
	}

	defer file.Close()

	info, err := file.Stat()

	if err != nil {
		return err
	}

	header, err := zip.FileInfoHeader(info)

	if err != nil {
		return err
	}

	header.Name = helper.SanitizedName(filename)

	writer, err := zipper.CreateHeader(header)

	if err != nil {
		return err
	}

	_, err = io.Copy(writer, file)

	return err
}
Exemplo n.º 2
0
func TestSanitizedName(filename []string) {
	newName := make([]string, len(filename))
	for key, name := range filename {
		newName[key] = helper.SanitizedName(name)
	}
	for _, name := range newName {
		fmt.Println(name)
	}
}