aboutsummaryrefslogtreecommitdiff
path: root/internal/bench/decompress.go
blob: 2eab0ad28bbe46cdd3c025369276a7d1cc0e3474 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//go:build ignore

package main

import (
	"fmt"
	"io"
	"os"

	"git.sr.ht/~runxiyu/furgit/internal/zlib"
)

func main() {
	if len(os.Args) != 3 {
		fmt.Fprintf(os.Stderr, "Usage: %s <input.zlib> <output>\n", os.Args[0])
		os.Exit(1)
	}

	inputFile := os.Args[1]
	outputFile := os.Args[2]

	in, err := os.Open(inputFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error opening input file: %v\n", err)
		os.Exit(1)
	}
	defer in.Close()

	out, err := os.Create(outputFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error creating output file: %v\n", err)
		os.Exit(1)
	}
	defer out.Close()

	reader, err := zlib.NewReader(in)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error creating zlib reader: %v\n", err)
		os.Exit(1)
	}
	defer reader.Close()

	_, err = io.Copy(out, reader)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error decompressing data: %v\n", err)
		os.Exit(1)
	}

	fmt.Fprintf(os.Stderr, "Successfully decompressed %s to %s\n", inputFile, outputFile)
}