當前位置: 首頁>>代碼示例>>Golang>>正文


Golang flate.NewReader函數代碼示例

本文整理匯總了Golang中compress/flate.NewReader函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewReader函數的具體用法?Golang NewReader怎麽用?Golang NewReader使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewReader函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的compress/flate.NewReader函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。