dongxiangxie8181 2015-10-29 15:17
浏览 175
已采纳

如何从解压缩的文件中删除gzip标头元数据

I've a gzip file that I try to decompress and save the result as follows:

bytesReader := bytes.NewReader(gzipData)
gzipReader, err := gzip.NewReader(bytesReader)
defer gzipReader.Close()
if err == nil {
    u1 := uuid.NewV4()
    filename := u1.String() + ".json"
    file, _ := os.Create(filename)
    defer file.Close()
    fileWriter := bufio.NewWriter(file)
    io.Copy(fileWriter, gzipReader)
    fileWriter.Flush()
} else {
    log.Println(err.Error())
}

When I check the resulting json file, I see that it starts with some metadata as follows:

$ head -n 1 caf12e7b-e5e5-4453-ac0f-4d1d02770632.json
data.json000644 000765 000024 00001562330 12614372206 013272 0ustar00elsoufystaff000000 000000 {... json content ...}

I'm getting this header whether the original file was created with gzip data.json or tar -czf data.tar.gz data.json. How I can remove the few first bytes from beeing writing to the output file?

  • 写回答

1条回答 默认 最新

  • dozrhldy285751 2015-10-29 22:34
    关注

    You generated your compressed file as an archive. The difference between compressing something and creating a compressed archive is, that an archive is a file format to contain more than one file, or complex structure (such as a file structure with folders).

    tar -cz <input files> creates an archive and compresses that using gzip, so you can have more than one file in a compressed tar archive.

    To compress a file in a typical UNIX/Linux environment, use the gzip command:

    $ gzip foo.json
    

    This will create a file foo.json.gz for you. To access its contents, use gunzip or zcat:

    $ zcat foo.json.gz
    <contents of foo.json>
    
    $ gunzip foo.json.gz
    $ cat foo.json
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?