• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang flate.NewReader函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中compress/flate.NewReader函数的典型用法代码示例。如果您正苦于以下问题:Golang NewReader函数的具体用法?Golang NewReader怎么用?Golang NewReader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewReader函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Inflate

// Inflate utility that decompresses a string using the flate algo
func Inflate(deflated []byte) []byte {
	var b bytes.Buffer
	r := flate.NewReader(bytes.NewReader(deflated))
	b.ReadFrom(r)
	r.Close()
	return b.Bytes()
}
开发者ID:wayf-dk,项目名称:gosaml,代码行数:8,代码来源:gosaml.go


示例2: Load

func (db *Database) Load(filename string) {
	var rows, columns uint32
	f, _ := os.Open(filename)
	c := flate.NewReader(f)
	r := bufio.NewReader(c)
	binary.Read(r, binary.LittleEndian, &rows)
	binary.Read(r, binary.LittleEndian, &columns)
	ids := make(map[string]int)
	db.ids = ids
	keys := make([]string, rows)
	db.keys = keys
	for i := 0; i < int(rows); i++ {
		b, _ := r.ReadBytes('\x00')
		key := string(b[:len(b)-1])
		keys[i] = key
		ids[key] = i
	}
	db.columns = make(map[string]*Column)
	for i := 0; i < int(columns); i++ {
		var id, count uint32
		name, _ := r.ReadBytes('\x00')
		binary.Read(r, binary.LittleEndian, &count)
		column := db.getColumn(string(name[:len(name)-1]))
		for j := 0; j < int(count); j++ {
			binary.Read(r, binary.LittleEndian, &id)
			column.Set(int(id), true)
		}
	}
	c.Close()
	f.Close()
}
开发者ID:wybiral,项目名称:stay,代码行数:31,代码来源:database.go


示例3: Parse

func (parser *redirectRequestParser) Parse(request *http.Request) (loginReq *AuthnRequest,
	relayState string, err error) {
	err = request.ParseForm()
	if err != nil {
		return
	}
	relayState = request.Form.Get("RelayState")
	if len(relayState) > 80 {
		err = errors.New("RelayState cannot be longer than 80 characters.")
		return
	}
	samlReq := request.Form.Get("SAMLRequest")
	// URL decoding is already performed
	// remove base64 encoding
	reqBytes, err := base64.StdEncoding.DecodeString(samlReq)
	if err != nil {
		return
	}
	// Remove deflate
	req := flate.NewReader(bytes.NewReader(reqBytes))
	// Read the XML
	decoder := xml.NewDecoder(req)
	loginReq = &AuthnRequest{}
	err = decoder.Decode(loginReq)
	return
}
开发者ID:justinwalz,项目名称:lite-idp,代码行数:26,代码来源:redirect.go


示例4: NewConnection

func NewConnection(nodeID string, reader io.Reader, writer io.Writer, receiver Model) Connection {
	cr := &countingReader{Reader: reader}
	cw := &countingWriter{Writer: writer}

	flrd := flate.NewReader(cr)
	flwr, err := flate.NewWriter(cw, flate.BestSpeed)
	if err != nil {
		panic(err)
	}
	wb := bufio.NewWriter(flwr)

	c := rawConnection{
		id:        nodeID,
		receiver:  nativeModel{receiver},
		reader:    flrd,
		cr:        cr,
		xr:        xdr.NewReader(flrd),
		writer:    flwr,
		cw:        cw,
		wb:        wb,
		xw:        xdr.NewWriter(wb),
		awaiting:  make([]chan asyncResult, 0x1000),
		indexSent: make(map[string]map[string][2]int64),
		outbox:    make(chan []encodable),
		nextID:    make(chan int),
		closed:    make(chan struct{}),
	}

	go c.readerLoop()
	go c.writerLoop()
	go c.pingerLoop()
	go c.idGenerator()

	return wireFormatConnection{&c}
}
开发者ID:Zypan,项目名称:syncthing,代码行数:35,代码来源:protocol.go


示例5: NewReaderDict

// NewReaderDict is like NewReader but uses a preset dictionary.
// NewReaderDict ignores the dictionary if the compressed data does not refer to it.
func NewReaderDict(r io.Reader, dict []byte) (io.ReadCloser, os.Error) {
	z := new(reader)
	if fr, ok := r.(flate.Reader); ok {
		z.r = fr
	} else {
		z.r = bufio.NewReader(r)
	}
	_, err := io.ReadFull(z.r, z.scratch[0:2])
	if err != nil {
		return nil, err
	}
	h := uint(z.scratch[0])<<8 | uint(z.scratch[1])
	if (z.scratch[0]&0x0f != zlibDeflate) || (h%31 != 0) {
		return nil, HeaderError
	}
	if z.scratch[1]&0x20 != 0 {
		_, err = io.ReadFull(z.r, z.scratch[0:4])
		if err != nil {
			return nil, err
		}
		checksum := uint32(z.scratch[0])<<24 | uint32(z.scratch[1])<<16 | uint32(z.scratch[2])<<8 | uint32(z.scratch[3])
		if checksum != adler32.Checksum(dict) {
			return nil, DictionaryError
		}
		z.decompressor = flate.NewReaderDict(z.r, dict)
	} else {
		z.decompressor = flate.NewReader(z.r)
	}
	z.digest = adler32.New()
	return z, nil
}
开发者ID:WXB506,项目名称:golang,代码行数:33,代码来源:reader.go


示例6: Decrypt

func Decrypt(key string, publickey PublicKey, rin io.Reader) (r io.Reader, length int64, sequence int64, e os.Error) {
	c, e := simpleCipher(key)
	if e != nil {
		e = os.NewError("Trouble reading the symmetric key: " + e.String())
		return
	}
	pub, e := readPublicKey(publickey)
	if e != nil {
		e = os.NewError("Trouble reading the public key: " + e.String())
		return
	}
	iv := make([]byte, c.BlockSize())
	_, e = io.ReadFull(rin, iv) // read the iv first (it's not encrypted)
	if e != nil {
		e = os.NewError("Trouble reading the iv: " + e.String())
		return
	}
	decrypter := cipher.NewCFBDecrypter(c, iv)
	rdec := flate.NewReader(cipher.StreamReader{decrypter, rin})
	e = binary.Read(rdec, binary.LittleEndian, &length)
	if e != nil {
		e = os.NewError("Trouble reading the file length: " + e.String())
		return
	}
	e = binary.Read(rdec, binary.LittleEndian, &sequence)
	if e != nil {
		e = os.NewError("Trouble reading the serial number: " + e.String())
		return
	}
	return &hashReader{rdec, sha256.New(), pub, length}, length, sequence, nil
}
开发者ID:andradeandrey,项目名称:goadmin,代码行数:31,代码来源:crypt.go


示例7: get

func (dz *reader) get(start, size int64) ([]byte, error) {

	if size == 0 {
		return []byte{}, nil
	}

	if start < 0 || size < 0 {
		return nil, fmt.Errorf("Negative start or size")
	}

	if int(start/dz.blocksize) >= len(dz.offsets) {
		return nil, fmt.Errorf("Start passed end of archive")
	}

	start1 := dz.blocksize * (start / dz.blocksize)
	size1 := size + (start - start1)

	dz.lock.Lock()
	defer dz.lock.Unlock()

	_, err := dz.fp.Seek(dz.offsets[start/dz.blocksize], 0)
	if err != nil {
		return nil, err
	}
	rd := flate.NewReader(dz.fp)

	data := make([]byte, size1)
	_, err = io.ReadFull(rd, data)
	if err != nil {
		return nil, err
	}

	return data[start-start1:], nil
}
开发者ID:postfix,项目名称:compactcorpus,代码行数:34,代码来源:dictzip.go


示例8: ExampleDecode

func ExampleDecode() {
	// In this example, we read a PBM (black and white) "file" (really a
	// hard-wired string to make the example self-contained) into a PPM
	// (color) image.  Because netpbm.Decode returns a netpbm.Image, not a
	// generic image.Image we can query its Netpbm format and maximum
	// value.  We also output an arbitrary white pixel to show how B&W can
	// be promoted to color.

	const pbmRaw = "\n0\xe1RVp\x0eru\f\xf1\x0f\xb2Rp\xf7\xf4\rP\b\xf0\xf3Up\xcb\xcc)I-R\bK-*\xce\xcc\xcfS0\xd43\xe423Q02\xe1\xfa\x0f\x02\xff\xfe\xff\x06\xd3\x1f\xec\x1b\xc1\xf4a{\x060\xddo\xc3\x01\xa6\xe5l*\xc0\xca\xea,~\x80\xe8?\u007f\n\u007f\x82\xe8\x9f\xff\x1eC\xe8\xff\xcf?\x02\xa9\v\xc6\xff\xfa?\xff\xff\xdf\xc0\xfd|A\xff\xe3\xff\x17\xe2\xff\x1fc\x90?\xfe\x83\xf5\xff\x97\xbeB\xfb\xe3M\xff\xff2\xcc\u007fd/\xbf\xff/\x03\xb7\xfc\xa1:\xf9\xff\f\xfc\xff\xed\xfbj\xec\xff\x89\xff\a\xd2\x15\xf5 \xe3\xed\xe4\x12\xc0\xd6\xd8\xd81\x82i\x81\u007f\xec`\x9a\xf1\u007f?\xd8\x19`\x1e\x1a\x00\x04\x00\x00\xff\xff"
	r := flate.NewReader(bytes.NewBufferString(pbmRaw))
	img, err := netpbm.Decode(r, &netpbm.DecodeOptions{
		Target:      netpbm.PPM, // Want to wind up with color
		Exact:       false,      // Can accept grayscale or B&W too
		PBMMaxValue: 42,         // B&W white --> (42, 42, 42)
	})
	if err != nil {
		panic(err)
	}
	r.Close()
	fmt.Printf("Image is of type %s.\n", img.Format())
	fmt.Printf("Maximum channel value is %d.\n", img.MaxValue())
	fmt.Printf("Color at (32, 20) is %#v.\n", img.At(32, 20))
	// Output:
	// Image is of type PPM.
	// Maximum channel value is 42.
	// Color at (32, 20) is npcolor.RGBM{R:0x2a, G:0x2a, B:0x2a, M:0x2a}.
}
开发者ID:tburke,项目名称:netpbm,代码行数:27,代码来源:example_test.go


示例9: Decompress

func Decompress(in []byte) []byte {
	buf := new(bytes.Buffer)
	decompressor := flate.NewReader(bytes.NewReader(in))
	io.Copy(buf, decompressor)
	decompressor.Close()
	return buf.Bytes()
}
开发者ID:skimata,项目名称:go-saml,代码行数:7,代码来源:compress.go


示例10: main

func main() {
	var file *os.File
	var err error

	if file, err = os.Open("output/sample.tar.flate"); err != nil {
		log.Fatalln(err)
	}
	defer file.Close()

	tr := tar.NewReader(flate.NewReader(file))

	var header *tar.Header
	for {
		header, err = tr.Next()
		if err == io.EOF {
			// ファイルの最後
			break
		}
		if err != nil {
			log.Fatalln(err)
		}

		buf := new(bytes.Buffer)
		if _, err = io.Copy(buf, tr); err != nil {
			log.Fatalln(err)
		}

		if err = ioutil.WriteFile("output/"+header.Name, buf.Bytes(), 0755); err != nil {
			log.Fatal(err)
		}
	}

}
开发者ID:qt-luigi,项目名称:golangcafe,代码行数:33,代码来源:readflate.go


示例11: Reader

func (r *ZipScannerImpl) Reader() (io.Reader, error) {
	switch r.fh.Method {
	case zip.Deflate:
		if r.Debug {
			fmt.Println("inflating...")
		}

		r.fr = flate.NewReader(r.reader)

	case zip.Store:
		if r.Debug {
			fmt.Println("reading...")
		}

		if r.fh.UncompressedSize > 0 {
			r.fr = io.LimitReader(r.reader, int64(r.fh.UncompressedSize))
		} else if r.fh.UncompressedSize == 0 && (r.fh.Flags&hasDataDescriptor) == 0 {
			// file of 0 bytes or directory ?
			r.fr = io.LimitReader(r.reader, 0)
		} else {
			return r.readError(NoUncompressedSize)
		}

	default:
		return r.readError(UnsupportedCompression)
	}

	r.err = nil
	return r.fr, r.err
}
开发者ID:raff,项目名称:zipscanner,代码行数:30,代码来源:zipscanner.go


示例12: DecompressString

func DecompressString(in string) string {
	buf := new(bytes.Buffer)
	decompressor := flate.NewReader(strings.NewReader(in))
	io.Copy(buf, decompressor)
	decompressor.Close()
	return buf.String()
}
开发者ID:skimata,项目名称:go-saml,代码行数:7,代码来源:compress.go


示例13: BodyReader

// BodyReader returns an io.ReadCloser that reads the HTTP request or response
// body. If mv.skipBody was set the reader will immediately return io.EOF.
//
// If the Decode option is passed the body will be unchunked if
// Transfer-Encoding is set to "chunked", and will decode the following
// Content-Encodings: gzip, deflate.
func (mv *MessageView) BodyReader(opts ...Option) (io.ReadCloser, error) {
	var r io.Reader

	conf := &config{}
	for _, o := range opts {
		o(conf)
	}

	br := bytes.NewReader(mv.message)
	r = io.NewSectionReader(br, mv.bodyoffset, mv.traileroffset-mv.bodyoffset)

	if !conf.decode {
		return ioutil.NopCloser(r), nil
	}

	if mv.chunked {
		r = httputil.NewChunkedReader(r)
	}
	switch mv.compress {
	case "gzip":
		gr, err := gzip.NewReader(r)
		if err != nil {
			return nil, err
		}
		return gr, nil
	case "deflate":
		return flate.NewReader(r), nil
	default:
		return ioutil.NopCloser(r), nil
	}
}
开发者ID:haijianren,项目名称:martian,代码行数:37,代码来源:messageview.go


示例14: Read

//Read returns a channel which logentries are appended to
//in sequential order
func (l *Logger) Read() <-chan model.LogEntry {
	c := make(chan model.LogEntry)

	go func(c chan<- model.LogEntry) {
		defer close(c)
		rFile, err := os.OpenFile(l.wFile.Name(), os.O_RDONLY, 0644)
		if err != nil {
			log.Fatal(err)
		}
		defer rFile.Close()

		reader := flate.NewReader(rFile)
		defer reader.Close()

		scanner := bufio.NewScanner(reader)
		scanner.Split(ScanPayloadSplitFunc)
		for scanner.Scan() {
			entry := model.LogEntry(scanner.Bytes())
			c <- entry
		}
		err = scanner.Err()
		if err != nil && err != io.ErrUnexpectedEOF {
			log.Fatal(err)
		}
	}(c)
	return c
}
开发者ID:netbrain,项目名称:goatpad,代码行数:29,代码来源:dlog.go


示例15: NewCompressedReadWriteCloser

func NewCompressedReadWriteCloser(rwc io.ReadWriteCloser) io.ReadWriteCloser {
	w, _ := flate.NewWriter(rwc, 1)
	return &compressedRWC{
		flate.NewReader(rwc),
		w,
	}
}
开发者ID:badgerodon,项目名称:go,代码行数:7,代码来源:compress.go


示例16: Download

func (self *Surf) Download(req Request) (resp *http.Response, err error) {
	param, err := NewParam(req)
	if err != nil {
		return nil, err
	}
	param.client = self.buildClient(param)
	resp, err = self.httpRequest(param)

	if err == nil {
		switch resp.Header.Get("Content-Encoding") {
		case "gzip":
			var gzipReader *gzip.Reader
			gzipReader, err = gzip.NewReader(resp.Body)
			if err == nil {
				resp.Body = gzipReader
			}

		case "deflate":
			resp.Body = flate.NewReader(resp.Body)

		case "zlib":
			var readCloser io.ReadCloser
			readCloser, err = zlib.NewReader(resp.Body)
			if err == nil {
				resp.Body = readCloser
			}
		}
	}

	resp = param.writeback(resp)

	return
}
开发者ID:ccsblueboy,项目名称:pholcus,代码行数:33,代码来源:surf.go


示例17: Website

func (a *Article) Website() io.ReadCloser {
	if a.WebsiteRaw != nil {
		return flate.NewReader(bytes.NewReader(a.WebsiteRaw))
	}

	return nil
}
开发者ID:akuendig,项目名称:go-paper,代码行数:7,代码来源:article.go


示例18: main

func main() {

	input, e := ioutil.ReadAll(os.Stdin)
	if e != nil {
		log.Fatal(e)
	}

	if isHttpPostBinding(input) {
		decoded, e := base64.StdEncoding.DecodeString(string(input))
		if e != nil {
			log.Fatal(e)
		}

		fmt.Print(string(decoded))

	} else {
		unescaped, e := url.QueryUnescape(string(input))
		if e != nil {
			log.Fatal(e)
		}

		decoded, e := base64.StdEncoding.DecodeString(unescaped)
		if e != nil {
			log.Fatal(e)
		}

		inflater := flate.NewReader(bytes.NewBuffer(decoded))

		io.Copy(os.Stdout, inflater)

		inflater.Close()
	}
}
开发者ID:kazuyamamoto,项目名称:samldec,代码行数:33,代码来源:samldec.go


示例19: readBody

func readBody(resp *http.Response) ([]byte, error) {
	buffer := bytes.NewBuffer(make([]byte, 0, 1024))
	var rd io.ReadCloser
	var err error
	switch resp.Header.Get("Content-Encoding") {
	case "gzip":
		rd, _ = gzip.NewReader(resp.Body)
		defer rd.Close()
	case "deflate":
		rd = flate.NewReader(resp.Body)
		defer rd.Close()
	default:
		rd = resp.Body
	}
	defer func() {
		e := recover()
		if e == nil {
			return
		}
		if panicErr, ok := e.(error); ok && panicErr == bytes.ErrTooLarge {
			err = panicErr
		} else {
			panic(e)
		}
	}()
	_, err = buffer.ReadFrom(rd)
	return buffer.Bytes(), err
}
开发者ID:Tigerfyj,项目名称:xunlei,代码行数:28,代码来源:util.go


示例20: Decompress

func (data *Data) Decompress() error {
	if !data.IsCompressed() {
		return nil
	}
	input := bytes.NewBuffer(data.Content)
	var reader io.Reader
	if data.ContentEncoding == ceDeflate {
		reader = flate.NewReader(input)
	} else if data.ContentEncoding == ceGzip {
		var err error
		if reader, err = gzip.NewReader(input); err != nil {
			return err
		}
	} else {
		return log.Error("unknown content-encoding",
			log.WithValue("content-encoding", data.ContentEncoding))
	}
	writer := bytes.Buffer{}
	_, err := io.Copy(&writer, reader)
	if err != nil {
		return err
	}
	data.Content = writer.Bytes()
	data.ContentEncoding = ""
	data.UncompressedLength = len(data.Content)
	return nil
}
开发者ID:software-projects,项目名称:go-exp,代码行数:27,代码来源:data.go



注:本文中的compress/flate.NewReader函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang flate.NewWriter函数代码示例发布时间:2022-05-24
下一篇:
Golang bzip2.NewReader函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap