Lines Matching refs:w
33 func NewWriter(w io.Writer) *Writer {
34 return &Writer{cw: &countWriter{w: bufio.NewWriter(w)}}
41 func (w *Writer) SetOffset(n int64) {
42 if w.cw.count != 0 {
45 w.cw.count = n
50 func (w *Writer) Flush() error {
51 return w.cw.w.(*bufio.Writer).Flush()
56 func (w *Writer) Close() error {
57 if w.last != nil && !w.last.closed {
58 if err := w.last.close(); err != nil {
61 w.last = nil
63 if w.closed {
66 w.closed = true
69 start := w.cw.count
70 for _, h := range w.dir {
111 if _, err := w.cw.Write(buf[:]); err != nil {
114 if _, err := io.WriteString(w.cw, h.Name); err != nil {
117 if _, err := w.cw.Write(h.Extra); err != nil {
120 if _, err := io.WriteString(w.cw, h.Comment); err != nil {
124 end := w.cw.count
126 records := uint64(len(w.dir))
152 if _, err := w.cw.Write(buf[:]); err != nil {
180 if _, err := w.cw.Write(buf[:]); err != nil {
184 return w.cw.w.(*bufio.Writer).Flush()
194 func (w *Writer) Create(name string) (io.Writer, error) {
199 return w.CreateHeader(header)
204 func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
206 return w.createHeaderImpl(fh)
220 func (w *Writer) createHeaderImpl(fh *FileHeader) (io.Writer, error) {
222 if w.last != nil && !w.last.closed {
223 if err := w.last.close(); err != nil {
227 if len(w.dir) > 0 && w.dir[len(w.dir)-1].FileHeader == fh {
238 zipw: w.cw,
239 compCount: &countWriter{w: w.cw},
242 comp := w.compressor(fh.Method)
251 fw.rawCount = &countWriter{w: fw.comp}
255 offset: uint64(w.cw.count),
257 w.dir = append(w.dir, h)
260 if err := writeHeader(w.cw, fh); err != nil {
264 w.last = fw
268 func writeHeader(w io.Writer, h *FileHeader) error {
317 if _, err := w.Write(buf[:]); err != nil {
320 if _, err := io.WriteString(w, h.Name); err != nil {
323 _, err := w.Write(h.Extra)
330 func (w *Writer) RegisterCompressor(method uint16, comp Compressor) {
331 if w.compressors == nil {
332 w.compressors = make(map[uint16]Compressor)
334 w.compressors[method] = comp
337 func (w *Writer) compressor(method uint16) Compressor {
338 comp := w.compressors[method]
355 func (w *fileWriter) Write(p []byte) (int, error) {
356 if w.closed {
359 w.crc32.Write(p)
360 return w.rawCount.Write(p)
364 func (w *fileWriter) close() (err error) {
366 if w.closed {
369 w.closed = true
370 if err := w.comp.Close(); err != nil {
375 fh := w.header.FileHeader
376 fh.CRC32 = w.crc32.Sum32()
377 fh.CompressedSize64 = uint64(w.compCount.count)
378 fh.UncompressedSize64 = uint64(w.rawCount.count)
412 _, err = w.zipw.Write(buf)
419 w io.Writer member
423 func (w *countWriter) Write(p []byte) (int, error) {
424 n, err := w.w.Write(p)
425 w.count += int64(n)
433 func (w nopCloser) Close() error {