golang:对字节数组进行gzip或zlib压缩时会偶尔出现卡顿的情况。

huangapple go评论74阅读模式
英文:

golang: gzip or zlib compression of byte array sporadically hangs

问题

我有以下函数来压缩一个字节数组:

func compress(input []byte) []byte {
    var buf bytes.Buffer
    compr := gzip.NewWriter(&buf)
    compr.Write(input) // 在这里它似乎会挂起,直到按下回车键
    compr.Close()
    output := buf.Bytes()

    return output
}

这个函数偶尔会挂起。当我按下[Enter]键时,函数会继续执行并返回预期的结果。我在这里漏掉了什么吗?

即使给出相同的输入,它也会大约五次中有一次挂起。无论我使用gzip还是zlib,都没有关系。

我在Linux x86_64上使用go 1.6。

英文:

I have the following function to compress a byte array:

func compress(input []byte) []byte {
        var buf bytes.Buffer
        compr := gzip.NewWriter(&buf)
        compr.Write(input) // here it appears to hang until
                           // Enter is pressed
        compr.Close()
        output := buf.Bytes()

        return output
}

Sporadically the function will hang. When I press [Enter] the function will continue and return the expected result. Am I missing something here?

It will hang about one times out of five, even when the same input is given. Whether I use gzip or zlib, it doesn't matter.

I am using go 1.6 on Linux x86_64

答案1

得分: 2

这不是代码或者Golang的问题。我使用的终端仿真器(terminator)似乎没有正确刷新。使用另一个终端仿真器,我无法重现这个错误。

英文:

It was not the code's or golang's fault. The terminal emulator I used (terminator) did not refresh properly, it seems. Using a different terminal emulator I could not reproduce the error.

huangapple
  • 本文由 发表于 2016年4月18日 21:30:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/36695470.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定