Files
requests/snappy.go
gospider 45c7a3262f sync
2025-07-11 11:54:33 +08:00

53 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package requests
import (
"io"
"github.com/golang/snappy"
)
// // 定义 snappy.Writer 池,包装 io.Writer
// var snappyWriterPool = sync.Pool{
// New: func() interface{} {
// // 先给一个空 buffer后面可以Reset替换输出目标
// return snappy.NewBufferedWriter(nil)
// },
// }
// // 定义 snappy.Reader 池,包装 io.Reader
// var snappyReaderPool = sync.Pool{
// New: func() interface{} {
// // 先给一个空 reader后面可以Reset替换输入来源
// return snappy.NewReader(nil)
// },
// }
// 获取并初始化 snappy.Writer
func getSnappyWriter(w io.Writer) *snappy.Writer {
return snappy.NewBufferedWriter(w)
// sw := snappyWriterPool.Get().(*snappy.Writer)
// sw.Reset(w)
// return sw
}
// 获取并初始化 snappy.Reader
func getSnappyReader(r io.Reader) *snappy.Reader {
return snappy.NewReader(r)
// sr := snappyReaderPool.Get().(*snappy.Reader)
// sr.Reset(r)
// return sr
}
// // 释放 snappy.Writer
// func putSnappyWriter(sw *snappy.Writer) {
// sw.Close()
// sw.Reset(nil)
// snappyWriterPool.Put(sw)
// }
// // 释放 snappy.Reader
// func putSnappyReader(sr *snappy.Reader) {
// sr.Reset(nil)
// snappyReaderPool.Put(sr)
// }