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条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)