LoginSignup
3
0

More than 3 years have passed since last update.

Goでzstd形式のディレクトリ圧縮をやってみた

Posted at

やりたいこと

Goでzstdを用いたディレクトリ圧縮をしたい。

zstdとは

facebookがOSS化した圧縮アルゴリズム。
他の圧縮アルゴリズムよりも圧縮展開速度・圧縮効率に優れている。らしい。

Goで使えんの?

ラッパーライブラリがありました。

リポジトリ: https://github.com/DataDog/zstd

godoc: https://godoc.org/github.com/DataDog/zstd

今回は上記を使用しますが、これ以外にもあるみたいです。

使ってみました

サンプルリポジトリ

tar, zstdパッケージを使用してsampleディレクトリをアーカイブ、圧縮しています。

ディレクトリ構成

$ tree .
.
├── Makefile
├── README.md
├── go.mod
├── go.sum
├── main.go
└── sample //圧縮対象のディレクトリ
    ├── bcat.txt
    ├── go
    │   └── go.txt
    └── hello.txt

2 directories, 8 files

コマンド

圧縮
sampleディレクトリを圧縮してsample.zstdを生成

$ go run main.go compress
sample
sample/bcat.txt
sample/go
sample/go/go.txt
sample/hello.txt
$ ls sample.zstd
sample.zstd

解凍
sample.zstdを解凍(outputディレクトリ配下を解凍先に指定)

$ go run main.go decompress
output/sample/bcat.txt
output/sample/go/go.txt
output/sample/hello.txt
$ tree output
output
└── sample
    ├── bcat.txt
    ├── go
    │   └── go.txt
    └── hello.txt

2 directories, 3 files

まとめ

細かい説明は端折っちゃいましたが、とりあえずGoでできました。

shellスクリプト等でもzstdでの圧縮はできますが、Goで書けるとプログラミング言語の恩恵を受けることができるので、選択肢の一つとして持っておくといいなと感じました。

参考

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0