dsfo22654 2013-06-03 05:46
浏览 330
已采纳

如何使用“ compress / gzip”包对文件进行gzip压缩?

I'm new to Go, and can't figure out how to use the compress/gzip package to my advantage. Basically, I just want to write something to a file, gzip it and read it directly from the zipped format through another script. I would really appreciate if someone could give me an example on how to do this.

  • 写回答

5条回答 默认 最新

  • dongsha7215 2013-06-03 06:00
    关注

    All the compress packages implement the same interface. You would use something like this to compress:

    var b bytes.Buffer
    w := gzip.NewWriter(&b)
    w.Write([]byte("hello, world
    "))
    w.Close()
    

    And this to unpack:

    r, err := gzip.NewReader(&b)
    io.Copy(os.Stdout, r)
    r.Close()
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 ssh登录页面的问题
  • ¥60 渗透一个指定银行app,拿到客户信息,需要什么级别
  • ¥50 关于在matlab上对曲柄摇杆机构上一点的运动学仿真
  • ¥15 jetson nano
  • ¥15 :app:debugCompileClasspath'.
  • ¥15 windows c++内嵌qt出现数据转换问题。
  • ¥20 公众号如何实现点击超链接后自动发送文字
  • ¥15 用php隐藏类名和增加类名
  • ¥15 算法设计与分析课程的提问
  • ¥15 用MATLAB汇总拟合图