golang中compress/bzip2

栏目: Go · 发布时间: 7年前

内容简介:一、bzip2的简介bzip2包实现bzip2的解压缩,bzip2是对单个文件进行压缩,可以先进行tar归档,然后进行压缩。二、bzip2的使用

一、bzip2的简介

bzip2包实现bzip2的解压缩,bzip2是对单个文件进行压缩,可以先进行tar归档,然后进行压缩。

二、bzip2的使用

go标准库中提供了一个对bzip2压缩包进行读取的操作,但是并没有提供进行bzip2压缩操作。

package main

import (
    "compress/bzip2"
    "os"
    "log"
    "fmt"
)

func main() {
    fz, err := os.Open("1.go.bz2")
    if err != nil {
        log.Fatal(err)
    }
    w := bzip2.NewReader(fz)
    buf := make([]byte, 1024 * 100)
    for {
        n, err := w.Read(buf)
        if n == 0 || err != nil {
            break
        }
        fmt.Println(string(buf[:n]))
    }
}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Pattern Recognition and Machine Learning

Pattern Recognition and Machine Learning

Christopher Bishop / Springer / 2007-10-1 / USD 94.95

The dramatic growth in practical applications for machine learning over the last ten years has been accompanied by many important developments in the underlying algorithms and techniques. For example,......一起来看看 《Pattern Recognition and Machine Learning》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具