當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


GO Writer.RegisterCompressor用法及代碼示例

GO語言"archive/zip"包中"Writer.RegisterCompressor"類型的用法及代碼示例。

用法:

func(w *Writer) RegisterCompressor(method uint16, comp Compressor)

RegisterCompressor 為特定方法 ID 注冊或覆蓋自定義壓縮器。如果沒有找到給定方法的壓縮器,Writer 將默認在包級別查找壓縮器。

例子:

package main

import (
	"archive/zip"
	"bytes"
	"compress/flate"
	"io"
)

func main() {
	// Override the default Deflate compressor with a higher compression level.

	// Create a buffer to write our archive to.
	buf := new(bytes.Buffer)

	// Create a new zip archive.
	w := zip.NewWriter(buf)

	// Register a custom Deflate compressor.
	w.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
		return flate.NewWriter(out, flate.BestCompression)
	})

	// Proceed to add files to w.
}

相關用法


注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Writer.RegisterCompressor。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。