func (w *Writer) Close() error {
	if w.last != nil && !w.last.closed {
		if err := w.last.close(); err != nil {
			return err
		}
		w.last = nil
	}
	if w.closed {
		return errors.New("zip: writer closed twice")
	}
	w.closed = true
	start := w.cw.count
	for _, h := range w.dir {
		var buf [directoryHeaderLen]byte
		b := writeBuf(buf[:])
		b.uint32(uint32(directoryHeaderSignature))
		b.uint16(h.CreatorVersion)
		b.uint16(h.ReaderVersion)
		b.uint16(h.Flags)
		b.uint16(h.Method)
		b.uint16(h.ModifiedTime)
		b.uint16(h.ModifiedDate)
		b.uint32(h.CRC32)
		if h.isZip64() || h.offset >= uint32max {
			b.uint32(uint32max)  
			b.uint32(uint32max)  
			var buf [28]byte  
			eb := writeBuf(buf[:])
			eb.uint16(zip64ExtraId)
			eb.uint16(24)  
			eb.uint64(h.UncompressedSize64)
			eb.uint64(h.CompressedSize64)
			eb.uint64(h.offset)
			h.Extra = append(h.Extra, buf[:]...)
		} else {
			b.uint32(h.CompressedSize)
			b.uint32(h.UncompressedSize)
		}
		b.uint16(uint16(len(h.Name)))
		b.uint16(uint16(len(h.Extra)))
		b.uint16(uint16(len(h.Comment)))
		b = b[4:]  
		b.uint32(h.ExternalAttrs)
		if h.offset > uint32max {
			b.uint32(uint32max)
		} else {
			b.uint32(uint32(h.offset))
		}
		if _, err := w.cw.Write(buf[:]); err != nil {
			return err
		}
		if _, err := io.WriteString(w.cw, h.Name); err != nil {
			return err
		}
		if _, err := w.cw.Write(h.Extra); err != nil {
			return err
		}
		if _, err := io.WriteString(w.cw, h.Comment); err != nil {
			return err
		}
	}
	end := w.cw.count
	records := uint64(len(w.dir))
	size := uint64(end - start)
	offset := uint64(start)
	if records > uint16max || size > uint32max || offset > uint32max {
		var buf [directory64EndLen + directory64LocLen]byte
		b := writeBuf(buf[:])
		b.uint32(directory64EndSignature)
		b.uint64(directory64EndLen - 12)  
		b.uint16(zipVersion45)            
		b.uint16(zipVersion45)            
		b.uint32(0)                       
		b.uint32(0)                       
		b.uint64(records)                 
		b.uint64(records)                 
		b.uint64(size)                    
		b.uint64(offset)                  
		b.uint32(directory64LocSignature)
		b.uint32(0)            
		b.uint64(uint64(end))  
		b.uint32(1)            
		if _, err := w.cw.Write(buf[:]); err != nil {
			return err
		}
		records = uint16max
		size = uint32max
		offset = uint32max
	}
	var buf [directoryEndLen]byte
	b := writeBuf(buf[:])
	b.uint32(uint32(directoryEndSignature))
	b = b[4:]                  
	b.uint16(uint16(records))  
	b.uint16(uint16(records))  
	b.uint32(uint32(size))     
	b.uint32(uint32(offset))   
	if _, err := w.cw.Write(buf[:]); err != nil {
		return err
	}
	return w.cw.w.(*bufio.Writer).Flush()
}
Close finishes writing the zip file by writing the central directory.
It does not (and can not) close the underlying writer.
package zip
import (
	"bufio"
	"encoding/binary"
	"errors"
	"hash"
	"io"
	"github.com/klauspost/crc32"
)
type Writer struct {
	cw          *countWriter
	dir         []*header
	last        *fileWriter
	closed      bool
	compressors map[uint16]Compressor
}
type header struct {
	*FileHeader
	offset uint64
}
func NewWriter(w io.Writer) *Writer {
	return &Writer{cw: &countWriter{w: bufio.NewWriter(w)}}
}
func (w *Writer) SetOffset(n int64) {
	if w.cw.count != 0 {
		panic("zip: SetOffset called after data was written")
	}
	w.cw.count = n
}
func (w *Writer) Flush() error {
	return w.cw.w.(*bufio.Writer).Flush()
}