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]))
    }
}

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

查看所有标签

猜你喜欢:

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

Software Engineering for Internet Applications

Software Engineering for Internet Applications

Eve Andersson、Philip Greenspun、Andrew Grumet / The MIT Press / 2006-03-06 / USD 35.00

After completing this self-contained course on server-based Internet applications software, students who start with only the knowledge of how to write and debug a computer program will have learned ho......一起来看看 《Software Engineering for Internet Applications》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

html转js在线工具
html转js在线工具

html转js在线工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具