Multiple:
- Updated README.md - Replaced old questions with cli arguments. - Added level of compression argument.
This commit is contained in:
parent
1a2ee9c5d5
commit
4eebc37ca7
13
README.md
13
README.md
|
@ -5,7 +5,16 @@ This is an application that allows you to compress to multiple compression syste
|
|||
run `go build main.go` and you're done!
|
||||
|
||||
# Usage:
|
||||
Run the executable and it'll ask you what file you are wanting to compress and where you'd like the output file to be.
|
||||
Here's an example on how to run it.
|
||||
|
||||
```
|
||||
./Digby -file file.ext -comp zstd -path /home/kiiwii -lvl 22
|
||||
```
|
||||
|
||||
`-file` is required -- tells Digby what file you want to compress.
|
||||
`-comp` is required -- tells Digby what compression algorithm you want to use (see [Supported Compression Systems](#supported-compression-systems))
|
||||
`-path` is optional -- tells Digby where to save the compressed file. If not specified it will save to the working directory.
|
||||
`-lvl` is optional -- tells Digby what level of compression to use. Only works when `-comp` is set to zstd. (If not specified it will default to level 5)
|
||||
|
||||
# Supported Compression Systems:
|
||||
- gzip
|
||||
|
@ -13,6 +22,6 @@ Run the executable and it'll ask you what file you are wanting to compress and w
|
|||
- zstd
|
||||
|
||||
# TODO:
|
||||
- [ ] Have command line arguments
|
||||
- [x] Have command line arguments
|
||||
- [ ] Support things such a `*` for selecting multiple files
|
||||
- [ ] Support compressing a folder
|
26
main.go
26
main.go
|
@ -8,6 +8,7 @@ import (
|
|||
"bufio"
|
||||
"compress/gzip"
|
||||
"compress/zlib"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -17,19 +18,24 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
// Asks user what file to compress and stores it as `file`
|
||||
fmt.Printf("What file would you like to copmress: ")
|
||||
|
||||
// -file argument, required.
|
||||
var file string
|
||||
fmt.Scanln(&file)
|
||||
flag.StringVar(&file, "file", "", "File to compress. (Required)")
|
||||
|
||||
// Asks user what dir to save the file.
|
||||
fmt.Printf("\n\nWhat directory would you like to save your file: ")
|
||||
// -path argument, optional
|
||||
var path string
|
||||
fmt.Scanln(&path)
|
||||
flag.StringVar(&path, "path", "", "Path to save the file. (Optional)")
|
||||
|
||||
fmt.Printf("\n\nWhat compression system: ")
|
||||
// -comp argument, required.
|
||||
var comp string
|
||||
fmt.Scanln(&comp)
|
||||
flag.StringVar(&comp, "comp", "", "Compression Algorithm. (Required)")
|
||||
|
||||
// -lvl argument, optional (only used for zstd.)
|
||||
var lvl int
|
||||
flag.Int("lvl", *&lvl, "Level of compression. (Optional)")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
// Compression shit
|
||||
f, _ := os.Open(*&path + *&file)
|
||||
|
@ -47,8 +53,10 @@ func main() {
|
|||
w.Close()
|
||||
} else if *&comp == "zstd" {
|
||||
f, _ = os.Create(*&path + *&file + ".zst")
|
||||
w := zstd.NewWriter(f)
|
||||
w := zstd.NewWriterLevel(f, *&lvl)
|
||||
w.Write(data)
|
||||
w.Close()
|
||||
}
|
||||
|
||||
fmt.Println("Successfully compressed ", *&file, " using ", *&comp)
|
||||
}
|
Loading…
Reference in New Issue