// CreateTestZip allows for creating temporary in memory zip files
CreateTestZip allows for creating temporary in memory zip files
// CreateTestZip allows for creating temporary in memory zip files
func CreateTestZip(files []TestFile) (io.ReadCloser, error) {
	buf := new(bytes.Buffer)
	zipWriter := zip.NewWriter(buf)
	for _, file := range files {
		zipFile, err := zipWriter.Create(file.Name)
		if err != nil {
			return nil, err
		}
		_, err = zipFile.Write([]byte(file.Body))
		if err != nil {
			return nil, err
		}
	}
	err := zipWriter.Close()
	if err != nil {
		return nil, err
	}
	return ioutil.NopCloser(buf), nil
}
func CreateTestZip ( files [ ] TestFile ) ( io . ReadCloser , error ) { buf := new ( bytes . Buffer ) zipWriter := zip . NewWriter ( buf ) for _ , file := range files { zipFile , err := zipWriter . Create ( file . Name ) if err != nil { return nil , err } _ , err = zipFile . Write ( [ ] byte ( file . Body ) ) if err != nil { return nil , err } } err := zipWriter . Close ( ) if err != nil { return nil , err } return ioutil . NopCloser ( buf ) , nil }
CreateTestZip allows for creating temporary in memory zip files
CreateTestZip allows for creating temporary in memory zip files
// Create a buffer to write our archive to. // Create a new zip archive. // Make sure to check the error on Close.