Programming-Idioms

New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
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;
...
import zipfile
with zipfile.ZipFile(name, 'w', zipfile.ZIP_DEFLATED) as zip:
    for file in list_:
        zip.write(file)