golang/go · error

zip: file closed twice

Error message

zip: file closed twice

What it means

Error "zip: file closed twice" thrown in golang/go.

Source

Thrown at src/archive/zip/writer.go:644

	compCount *countWriter
	crc32     hash.Hash32
	closed    bool
}

func (w *fileWriter) Write(p []byte) (int, error) {
	if w.closed {
		return 0, errors.New("zip: write to closed file")
	}
	if w.raw {
		return w.zipw.Write(p)
	}
	w.crc32.Write(p)
	return w.rawCount.Write(p)
}

func (w *fileWriter) close() error {
	if w.closed {
		return errors.New("zip: file closed twice")
	}
	w.closed = true
	if w.raw {
		return w.writeDataDescriptor()
	}
	if err := w.comp.Close(); err != nil {
		return err
	}

	// update FileHeader
	fh := w.header.FileHeader
	fh.CRC32 = w.crc32.Sum32()
	fh.CompressedSize64 = uint64(w.compCount.count)
	fh.UncompressedSize64 = uint64(w.rawCount.count)

	if w.CompressedSize64 > uint32max || w.UncompressedSize64 > uint32max {
		fh.CompressedSize = uint32max
		fh.UncompressedSize = uint32max

View on GitHub (pinned to b6b368adc5)

When it happens

Trigger: Thrown at src/archive/zip/writer.go:644 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/9ce0103546fe3138. Report an issue: GitHub.