?
本文檔使用 php中文網(wǎng)手冊(cè) 發(fā)布
import "compress/lzw"
概述
索引
軟件包 lzw 實(shí)現(xiàn)了 Le Welpel-Ziv-Welch 壓縮數(shù)據(jù)格式,在TA Welch 的“A Technique for High-Performance Data Compression(一種用于高性能數(shù)據(jù)壓縮的技術(shù))”Computer, 17(6) (June 1984), pp 8-19.
特別是,它實(shí)現(xiàn)了 GIF 和 PDF 文件格式所使用的 LZW,這意味著可變寬度代碼可達(dá) 12 位,前兩個(gè)非文字代碼是一個(gè)清晰的代碼和一個(gè) EOF 代碼。
TIFF 文件格式使用類似但不兼容的LZW算法。有關(guān)實(shí)現(xiàn),請(qǐng)參閱golang.org/x/image/tiff/lzw 軟件包。
func NewReader(r io.Reader, order Order, litWidth int) io.ReadCloser
func NewWriter(w io.Writer, order Order, litWidth int) io.WriteCloser
type Order
reader.go writer.go
func NewReader(r io.Reader, order Order, litWidth int) io.ReadCloser
NewReader 創(chuàng)建一個(gè)新的 io.ReadCloser。從返回的io.ReadCloser 中讀取并解壓縮來(lái)自r的數(shù)據(jù)。如果 r 不執(zhí)行io.ByteReader,則解壓縮程序可能從 r 讀取比所需更多的數(shù)據(jù)。完成閱讀時(shí),調(diào)用者有責(zé)任在 ReadCloser 上調(diào)用 Close。用于文字代碼的位數(shù) litWidth 必須在2,8范圍內(nèi),通常為8。它必須等于壓縮過(guò)程中使用的 litWidth。
func NewWriter(w io.Writer, order Order, litWidth int) io.WriteCloser
NewWriter 創(chuàng)建一個(gè)新的 io.WriteCloser。寫(xiě)入返回的io.WriteCloser 被壓縮并寫(xiě)入w。撰寫(xiě)完成后,調(diào)用者有責(zé)任在WriteCloser 上調(diào)用 Close。用于文字代碼的位數(shù) litWidth 必須在2,8 范圍內(nèi),通常為 8.輸入字節(jié)必須小于 1<<litWidth。
Order 指定 LZW 數(shù)據(jù)流中的位排序。
type Order int
const ( // LSB首先表示最低有效位,如GIF文件格式中所用。 LSB Order = iota // MSB意味著首先使用最高有效位,如TIFF和PDF中所用 // 文件格式。 MSB)