dongqiancui9194 2018-02-08 11:53
浏览 34
已采纳

进行GZIP冲洗并确定尺寸

I am creating GZIPs on demand by streaming data, but I need to split it because the receving end has a hard code limit. When I Flush() and Close(), I see that the underyling byte buffer grows by 13 bytes. I looked at the source code of Gzip Close:

func (z *Writer) Close() error {
    if z.err != nil {
        return z.err
    }
    if z.closed {
        return nil
    }
    z.closed = true
    if !z.wroteHeader {
        z.Write(nil)
        if z.err != nil {
            return z.err
        }
    }
    z.err = z.compressor.Close()
    if z.err != nil {
        return z.err
    }
    le.PutUint32(z.buf[:4], z.digest)
    le.PutUint32(z.buf[4:8], z.size)
    _, z.err = z.w.Write(z.buf[:8])
    return z.err
}

It indeed writes something but is there someway to determine it more pragmatic than just saying 13 bytes? There can be headers etc. I just want to have a safe margin, is there any possibilities that it can grow way larger than 13 bytes? I can happily set 1kb margin and live with it.

  • 写回答

2条回答 默认 最新

  • duanlanqian9974 2018-02-08 18:45
    关注

    The 13 bytes are the maximum value to my knowledge. 8 bytes come from the gzip footer, the two PutUint32 calls. The other 5 bytes are added by the huffmann compressor which ads an empty final block when the compressor is closed. It will add 3 bits (= 1 byte) for the final block header and 2 bytes for the length 0 and another 2 bytes which are inverted length 0xffff. So i assume you can calculate with those 13 bytes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示