blob: f4f016051b1238332c91604a8d964ce827f3e4fd [file] [log] [blame]
Nigel Taod0f05912022-06-21 22:58:52 +10001// Copyright 2022 The Wuffs Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//go:build ignore
16// +build ignore
17
18package main
19
20// litonlylzma.go converts to and from the Literal Only LZMA compressed file
21// format, a subset of the LZMA compressed file format (e.g. as spoken by
22// /usr/bin/lzma on a Debian system).
23//
24// Usage:
25// go run litonlylzma.go -encode < foo.txt > foo.txt.litonlylzma
26// go run litonlylzma.go -decode < foo.txt.litonlylzma
27
28import (
29 "flag"
30 "fmt"
31 "io"
32 "os"
33
34 "github.com/google/wuffs/lib/litonlylzma"
35)
36
37var (
38 decode = flag.Bool("decode", false, "decode from LZMA")
39 encode = flag.Bool("encode", false, "encode to LZMA")
40)
41
42func main() {
43 if err := main1(); err != nil {
44 os.Stderr.WriteString(err.Error() + "\n")
45 os.Exit(1)
46 }
47}
48
49func main1() error {
50 flag.Parse()
51 if *decode == *encode {
52 return fmt.Errorf("exactly one of -decode and -encode needed")
53 }
54 src, err := io.ReadAll(os.Stdin)
55 if err != nil {
56 return err
57 }
58 dst, err := []byte(nil), error(nil)
59 if *decode {
60 dst, _, err = litonlylzma.FileFormatLZMA.Decode(nil, src)
61 } else {
62 dst, err = litonlylzma.FileFormatLZMA.Encode(nil, src)
63 }
64 if err != nil {
65 return err
66 }
67 _, err = os.Stdout.Write(dst)
68 return err
69}