GO語言"compress/zlib"包中"NewReader"函數的用法及代碼示例。
用法:
func NewReader(r io.Reader)(io.ReadCloser, error)
NewReader 創建一個新的 ReadCloser 從返回的 ReadCloser 讀取從 r 讀取和解壓縮數據。如果 r 沒有實現 io ByteReader,則解壓縮器可能會從 r 讀取比必要更多的數據。調用者有責任在完成後在ReadCloser 上調用 Close。
NewReader 返回的ReadCloser 也實現了Resetter。
例子:
package main
import (
"bytes"
"compress/zlib"
"io"
"os"
)
func main() {
buff := []byte{120, 156, 202, 72, 205, 201, 201, 215, 81, 40, 207,
47, 202, 73, 225, 2, 4, 0, 0, 255, 255, 33, 231, 4, 147}
b := bytes.NewReader(buff)
r, err := zlib.NewReader(b)
if err != nil {
panic(err)
}
io.Copy(os.Stdout, r)
r.Close()
}
輸出:
hello, world
相關用法
- GO NewReplacer用法及代碼示例
- GO NewFromFiles用法及代碼示例
- GO NewCBCDecrypter用法及代碼示例
- GO NewCFBDecrypter用法及代碼示例
- GO NewCFBEncrypter用法及代碼示例
- GO New用法及代碼示例
- GO NewGCM用法及代碼示例
- GO NewTripleDESCipher用法及代碼示例
- GO NewWriter用法及代碼示例
- GO NewCBCEncrypter用法及代碼示例
- GO NewOFB用法及代碼示例
- GO NewTLSServer用法及代碼示例
- GO NewTicker用法及代碼示例
- GO NewCTR用法及代碼示例
- GO NewEncoder用法及代碼示例
- GO NumError用法及代碼示例
- GO NotifyContext用法及代碼示例
- GO Node用法及代碼示例
- GO Notify用法及代碼示例
- GO NotFoundHandler用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 NewReader。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。