本文整理汇总了Golang中compress/zlib.NewWriterLevel函数的典型用法代码示例。如果您正苦于以下问题:Golang NewWriterLevel函数的具体用法?Golang NewWriterLevel怎么用?Golang NewWriterLevel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewWriterLevel函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: defineSchemaVar
func (g *generator) defineSchemaVar() error {
msg, seg, _ := capnp.NewMessage(capnp.SingleSegment(nil))
req, _ := schema.NewRootCodeGeneratorRequest(seg)
fnodes := g.nodes[g.fileID].nodes
ids := make([]uint64, len(fnodes))
for i, n := range fnodes {
ids[i] = n.Id()
}
sort.Sort(uint64Slice(ids))
// TODO(light): find largest object size and use that to allocate list
nodes, _ := req.NewNodes(int32(len(g.nodes)))
i := 0
for _, id := range ids {
n := g.nodes[id]
if err := nodes.Set(i, n.Node); err != nil {
return err
}
i++
}
var buf bytes.Buffer
z, _ := zlib.NewWriterLevel(&buf, zlib.BestCompression)
if err := capnp.NewPackedEncoder(z).Encode(msg); err != nil {
return err
}
if err := z.Close(); err != nil {
return err
}
return renderSchemaVar(g.r, schemaVarParams{
G: g,
FileID: g.fileID,
NodeIDs: ids,
schema: buf.Bytes(),
})
}
开发者ID:zombiezen,项目名称:go-capnproto2,代码行数:34,代码来源:capnpc-go.go
示例2: SaveRequest
func (rw *RedisWrapper) SaveRequest(req *ParsedRequest, creatives []*Inventory, timeout int) error {
conn := rw.redisPool.Get()
defer conn.Close()
creativesForRedis := make([]*InventoryForRedis, len(creatives))
for index, value := range creatives {
creativesForRedis[index] = &InventoryForRedis{
AdId: value.AdId,
Frequency: value.Frequency,
}
}
req.Creatives = creativesForRedis
body, err := json.Marshal(*req)
if err != nil {
return err
}
var buf bytes.Buffer
zlibWriter, err := zlib.NewWriterLevel(&buf, zlib.BestSpeed)
if err != nil {
return err
}
if _, err := zlibWriter.Write(body); err != nil {
return err
}
zlibWriter.Close()
if _, err := conn.Do("setex", rw.configure.RedisCachePrefix+req.Id, timeout, buf.Bytes()); err != nil {
rw.logger.Warning("redis error: %v", err.Error())
return err
}
return nil
}
开发者ID:yangzhao28,项目名称:rtblite,代码行数:30,代码来源:redis.go
示例3: SerializeCompressed
// SerializeCompressed serializes a compressed data packet to w and
// returns a WriteCloser to which the literal data packets themselves
// can be written and which MUST be closed on completion. If cc is
// nil, sensible defaults will be used to configure the compression
// algorithm.
func SerializeCompressed(w io.WriteCloser, algo CompressionAlgo, cc *CompressionConfig) (literaldata io.WriteCloser, err error) {
compressed, err := serializeStreamHeader(w, packetTypeCompressed)
if err != nil {
return
}
_, err = compressed.Write([]byte{uint8(algo)})
if err != nil {
return
}
level := DefaultCompression
if cc != nil {
level = cc.Level
}
var compressor io.WriteCloser
switch algo {
case CompressionZIP:
compressor, err = flate.NewWriter(compressed, level)
case CompressionZLIB:
compressor, err = zlib.NewWriterLevel(compressed, level)
default:
s := strconv.Itoa(int(algo))
err = errors.UnsupportedError("Unsupported compression algorithm: " + s)
}
if err != nil {
return
}
literaldata = compressedWriteCloser{compressed, compressor}
return
}
开发者ID:AlphaStaxLLC,项目名称:rocket,代码行数:39,代码来源:compressed.go
示例4: Start
func (o *PrtGenerator) Start(outFilename string, total int, maxProcs int, boundary *BoundaryLocator) {
o.enclosedsChan = make(chan *EnclosedChunkJob, maxProcs*2)
o.completeChan = make(chan bool)
o.total = total
o.boundary = boundary
maxProcs = 1
for i := 0; i < maxProcs; i++ {
go o.chunkProcessor()
}
var openErr os.Error
o.outFile, openErr = os.Open(outFilename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if openErr != nil {
fmt.Fprintln(os.Stderr, openErr) // TODO: return openErr
return
}
o.w = bufio.NewWriter(o.outFile)
WriteHeader(o.w, -1, []ChannelDefinition{{"Position", 4, 3, 0}, {"BlockID", 1, 1, 12}})
var zErr os.Error
o.zw, zErr = zlib.NewWriterLevel(o.w, zlib.NoCompression)
if zErr != nil {
fmt.Fprintln(os.Stderr, zErr) // TODO: return zErr
return
}
}
开发者ID:danielrh,项目名称:mcobj,代码行数:29,代码来源:prt.go
示例5: sliceCompress
// Returns a zlib-compressed copy of the specified byte array
func sliceCompress(data []byte) []byte {
var buf bytes.Buffer
cmp, _ := zlib.NewWriterLevel(&buf, zlib.BestSpeed)
cmp.Write(data)
cmp.Close()
return buf.Bytes()
}
开发者ID:stanim,项目名称:gofpdf,代码行数:8,代码来源:util.go
示例6: Flush
func (f *Ftail) Flush() error {
if f.buf.Len() <= 0 {
return nil
}
var b bytes.Buffer
w, err := zlib.NewWriterLevel(&b, zlib.BestCompression)
if err != nil {
return err
}
row := core.Row{Time: f.lastTime, Pos: f.Pos}
row.Text = f.buf.String()
_, err = io.Copy(w, &f.buf)
if cerr := w.Close(); cerr != nil {
log.Printf("zlib close err:%s", cerr)
}
if err != nil {
return err
}
if b.Len() < f.buf.Len() {
row.Bin = b.Bytes()
row.Text = ""
}
//log.Printf("text:'%s',bin:'%x', buf.String:%s", row.Text, row.Bin, f.buf.String())
defer f.buf.Reset()
if err = f.rec.Put(row); err != nil {
log.Printf("Flush %s err:%s", f.Pos.Name, err)
}
return err
}
开发者ID:masahide,项目名称:ftailer,代码行数:29,代码来源:ftail.go
示例7: CompressData
//func CompressData(in []byte) (data *bytes.Buffer, err error) {
func CompressData(in []byte) (out []byte, err error) {
if len(in) == 0 {
return nil, &AcError{Value: -1, Msg: "CompressData() invalid input: ", Err: err}
}
// first let's compress
data := new(bytes.Buffer)
zbuf, err := zlib.NewWriterLevel(data, zlib.BestCompression)
if err != nil {
return nil, &AcError{Value: -2, Msg: "CompressData().zlib.NewWriterLevel(): ", Err: err}
}
n, err := zbuf.Write(in)
if err != nil || n != len(in) {
return nil, &AcError{Value: -3, Msg: "CompressData().zlib.Write(): ", Err: err}
}
//XXX funny Flush don't actually flush stuff from zlib into the writer all the time.....
//zbuf.Flush()
// XXX let's try...
zbuf.Close()
//fmt.Fprintf(os.Stderr, "CompressData(%d B): %d B\n", len(in), data.Len())
out = data.Bytes()
return out, nil
}
开发者ID:unix4fun,项目名称:ac,代码行数:28,代码来源:utils.go
示例8: compress
func compress(s string) string {
var b bytes.Buffer
w, _ := zlib.NewWriterLevel(&b, zlib.BestSpeed) // flate.BestCompression
w.Write([]byte(s))
w.Close()
return b.String()
}
开发者ID:Kewtt,项目名称:scramble,代码行数:7,代码来源:smtp_server.go
示例9: NewPacketCodecZlibLevel
func NewPacketCodecZlibLevel(threshold int, level int) (this *PacketCodecZlib) {
this = new(PacketCodecZlib)
this.threshold = threshold
this.level = level
this.zlibWriter, _ = zlib.NewWriterLevel(nil, level)
return
}
开发者ID:0xNiklas,项目名称:GoLilyPad,代码行数:7,代码来源:packetCodecZlib.go
示例10: Generate
func (pp *pendingPayload) Generate(hostname string) (err error) {
var buffer bytes.Buffer
// Begin with the nonce
if _, err = buffer.Write([]byte(pp.nonce)); err != nil {
return
}
var compressor *zlib.Writer
if compressor, err = zlib.NewWriterLevel(&buffer, 3); err != nil {
return
}
// Append all the events
for _, event := range pp.events[pp.ack_events:] {
// Add host field
event.Event["host"] = hostname
if err = pp.bufferJdatDataEvent(compressor, event); err != nil {
return
}
}
compressor.Close()
pp.payload = buffer.Bytes()
pp.payload_start = pp.ack_events
return
}
开发者ID:pascalrobert,项目名称:log-courier,代码行数:29,代码来源:pending_payload.go
示例11: Start
func (o *PrtGenerator) Start(outFilename string, total int, maxProcs int, boundary *BoundaryLocator) error {
o.enclosedsChan = make(chan *EnclosedChunkJob, maxProcs*2)
o.completeChan = make(chan bool)
o.total = total
o.boundary = boundary
maxProcs = 1
for i := 0; i < maxProcs; i++ {
go o.chunkProcessor()
}
var openErr error
o.outFile, openErr = os.Create(outFilename)
if openErr != nil {
return openErr
}
o.w = bufio.NewWriter(o.outFile)
WriteHeader(o.w, -1, []ChannelDefinition{{"Position", 4, 3, 0}, {"BlockID", 1, 1, 12}})
var zErr error
o.zw, zErr = zlib.NewWriterLevel(o.w, zlib.NoCompression)
if zErr != nil {
return zErr
}
return nil
}
开发者ID:quag,项目名称:mcobj,代码行数:29,代码来源:prt.go
示例12: printResponse
func (h Handler) printResponse(status int, header map[string]string, content []byte) {
headerEncoded := encodeData(header)
h.response.WriteHeader(200)
h.response.Header().Set("Content-Type", "image/gif")
compressed := false
if contentType, ok := header["content-type"]; ok {
if strings.HasPrefix(contentType, "text/") || strings.HasPrefix(contentType, "application/json") || strings.HasPrefix(contentType, "application/javascript") {
compressed = true
}
}
if compressed {
h.response.Write([]byte("1"))
w, err := zlib.NewWriterLevel(h.response, zlib.BestCompression)
if err != nil {
h.context.Criticalf("zlib.NewWriterDict(h.response, zlib.BestCompression, nil) Error: %v", err)
return
}
defer w.Close()
binary.Write(w, binary.BigEndian, uint32(status))
binary.Write(w, binary.BigEndian, uint32(len(headerEncoded)))
binary.Write(w, binary.BigEndian, uint32(len(content)))
w.Write(headerEncoded)
w.Write(content)
} else {
h.response.Write([]byte("0"))
binary.Write(h.response, binary.BigEndian, uint32(status))
binary.Write(h.response, binary.BigEndian, uint32(len(headerEncoded)))
binary.Write(h.response, binary.BigEndian, uint32(len(content)))
h.response.Write(headerEncoded)
h.response.Write(content)
}
}
开发者ID:yuexia12,项目名称:goagent,代码行数:35,代码来源:fetch.go
示例13: newLumberjackClient
func newLumberjackClient(
conn TransportClient,
compressLevel int,
maxWindowSize int,
timeout time.Duration,
beat string,
) (*lumberjackClient, error) {
// validate by creating and discarding zlib writer with configured level
if compressLevel > 0 {
tmp := bytes.NewBuffer(nil)
w, err := zlib.NewWriterLevel(tmp, compressLevel)
if err != nil {
return nil, err
}
w.Close()
}
encodedBeat, err := json.Marshal(beat)
if err != nil {
return nil, err
}
return &lumberjackClient{
TransportClient: conn,
windowSize: defaultStartMaxWindowSize,
timeout: timeout,
maxWindowSize: maxWindowSize,
compressLevel: compressLevel,
beat: encodedBeat,
}, nil
}
开发者ID:Ingensi,项目名称:dockerbeat,代码行数:32,代码来源:client.go
示例14: Encode
func (this *PacketCodecZlib) Encode(writer io.Writer, util []byte, packet Packet) (err error) {
buffer := new(bytes.Buffer)
err = this.codec.Encode(buffer, util, packet)
if err != nil {
return
}
if raw, ok := packet.(PacketRaw); ok && raw.Raw() {
_, err = buffer.WriteTo(writer)
} else if buffer.Len() < this.threshold {
err = WriteVarInt(writer, util, 0)
if err != nil {
return
}
_, err = buffer.WriteTo(writer)
} else {
err = WriteVarInt(writer, util, buffer.Len())
if err != nil {
return
}
var zlibWriter io.WriteCloser
zlibWriter, err = zlib.NewWriterLevel(writer, this.level)
if err != nil {
return
}
_, err = buffer.WriteTo(zlibWriter)
if err != nil {
return
}
err = zlibWriter.Close()
}
return
}
开发者ID:LivousCraftNetwork,项目名称:GoLilyPad,代码行数:32,代码来源:packetCodecZlib.go
示例15: packRequest
func (c *conn) packRequest(r *http.Request) (*http.Request, error) {
buf := &bytes.Buffer{}
zbuf, err := zlib.NewWriterLevel(buf, zlib.BestCompression)
if err != nil {
return nil, fmt.Errorf("conn.packRequest(zlib.NewWriterLevel)>%s", err)
}
url := c.url + r.URL.String()
urlhex := make([]byte, hex.EncodedLen(len(url)))
hex.Encode(urlhex, []byte(url))
fmt.Fprintf(zbuf, "url=%s", urlhex)
fmt.Fprintf(zbuf, "&method=%s", hex.EncodeToString([]byte(r.Method)))
if c.ps.password != "" {
fmt.Fprintf(zbuf, "&password=%s", c.ps.password)
}
fmt.Fprint(zbuf, "&headers=")
for k, v := range r.Header {
fmt.Fprint(zbuf, hex.EncodeToString([]byte(fmt.Sprintf("%s:%s\r\n", k, v[0]))))
}
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return nil, fmt.Errorf("conn.packRequest(ioutil.ReadAll(r.Body))>%s", err)
}
payload := hex.EncodeToString(body)
fmt.Fprintf(zbuf, "&payload=%s", payload)
zbuf.Close()
req, err := http.NewRequest("POST", c.ps.path, buf)
if err != nil {
return nil, fmt.Errorf("conn.packRequest(http.NewRequest)>%s", err)
}
req.Host = c.ps.appid[rand.Intn(len(c.ps.appid))] + ".appspot.com"
req.URL.Scheme = "http"
return req, nil
}
开发者ID:shitfSign,项目名称:goagent-go,代码行数:33,代码来源:proxy.go
示例16: BenchmarkWriteWithBestZlibCompression
func BenchmarkWriteWithBestZlibCompression(b *testing.B) {
file := benchFile()
w, _ := zlib.NewWriterLevel(file, zlib.BestCompression)
benchmarkWrite(b, w)
fi, _ := file.Stat()
b.SetBytes(int64(int(fi.Size()) / 1024 / 1024))
}
开发者ID:netbrain,项目名称:goatpad,代码行数:7,代码来源:dlog_test.go
示例17: newZlibWriter
func newZlibWriter() *zlib.Writer {
writer, err := zlib.NewWriterLevel(new(bytes.Buffer), gzip.BestSpeed)
if err != nil {
panic(err.Error())
}
return writer
}
开发者ID:GaizkaRubio,项目名称:mesos-dns,代码行数:7,代码来源:compressor_pools.go
示例18: newClientProcol
func newClientProcol(
conn net.Conn,
timeout time.Duration,
compressLevel int,
beat string,
) (*protocol, error) {
// validate by creating and discarding zlib writer with configured level
if compressLevel > 0 {
tmp := bytes.NewBuffer(nil)
w, err := zlib.NewWriterLevel(tmp, compressLevel)
if err != nil {
return nil, err
}
w.Close()
}
encodedBeat, err := json.Marshal(beat)
if err != nil {
return nil, err
}
return &protocol{
conn: conn,
timeout: timeout,
compressLevel: compressLevel,
eventsBuffer: bytes.NewBuffer(nil),
beat: encodedBeat,
}, nil
}
开发者ID:radoondas,项目名称:apachebeat,代码行数:30,代码来源:protocol.go
示例19: loadFont
func loadFont(f *fontdata) (font *FontMetrics) {
var err error
if font, err = ParseFontMetricsFile(f.Metrics, f.Label); err != nil {
log.Fatalf("loading font metrics: %v", err)
}
if f.StemV > 0 && font.StemV <= 0 {
font.StemV = f.StemV
}
if len(f.FontFile) > 0 {
font.File = []byte(f.FontFile)
var buf bytes.Buffer
var writer *zlib.Writer
if writer, err = zlib.NewWriterLevel(&buf, zlib.BestCompression); err != nil {
log.Fatal("Setting up zlib compressor: ", err)
}
if _, err = writer.Write(font.File); err != nil {
log.Fatal("Writing to zlib compressor: ", err)
}
if err = writer.Close(); err != nil {
log.Fatal("Closing zlib compressor: ", err)
}
font.CompressedFile = buf.Bytes()
}
return
}
开发者ID:renquinn,项目名称:warddirectory,代码行数:27,代码来源:font.go
示例20: compress
// compress uses zlib to compress stuff, for transferring big stuff like
// stdout, stderr and environment variables over the network, and for storing
// of same on disk
func compress(data []byte) []byte {
var compressed bytes.Buffer
w, _ := zlib.NewWriterLevel(&compressed, zlib.BestCompression)
w.Write(data)
w.Close()
return compressed.Bytes()
}
开发者ID:sb10,项目名称:vrpipe,代码行数:10,代码来源:utils.go
注:本文中的compress/zlib.NewWriterLevel函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论