This language bar is your friend. Select your favorite languages!

Idiom #217 Create a Zip archive

Create a zip-file with filename name and add the files listed in list to that zip-file.

import zipfile
with zipfile.ZipFile(name, 'w', zipfile.ZIP_DEFLATED) as zip:
    for file in list_:
        zip.write(file)
import "archive/zip"
import "bytes"
import "os"
import "io"
import "io/ioutil"
buf := new(bytes.Buffer)
w := zip.NewWriter(buf)
for _, filename := range list {
	input, err := os.Open(filename)
	if err != nil {
		return err
	}
	output, err := w.Create(filename)
	if err != nil {
		return err
	}
	_, err = io.Copy(output, input)
	if err != nil {
		return err
	}
}

err := w.Close()
if err != nil {
	return err
}

err = ioutil.WriteFile(name, buf.Bytes(), 0777)
if err != nil {
	return err
}
Zipper, Classes
...
  Zip := TZipper.Create;
  Zip.FileName := name;
  Zip.Entries.AddFileEntries(list);
  Zip.ZipAllFiles;
  Zip.Free;
...

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

Bart