Skip to content

Commit

Permalink
Release version 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Apr 8, 2024
2 parents 7c86853 + 8439c3e commit ff00296
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 113 deletions.
4 changes: 2 additions & 2 deletions .bumpversion.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# SPDX-License-Identifier: Apache-2.0 OR MIT

[tool.bumpversion]
current_version = "0.3.0"
current_version = "0.3.1"

[[tool.bumpversion.files]]
filename = "cmd/glzip/main.go"
filename = "cmd/glzip/cli.go"

[[tool.bumpversion.files]]
filename = "docs/man/man1/glzip.1.adoc"
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ All notable changes to this project will be documented in this file.
The format is based on https://keepachangelog.com/[Keep a Changelog], and this
project adheres to https://semver.org/[Semantic Versioning].

== {compare-url}/v0.3.0\...v0.3.1[0.3.1] - 2024-04-08

=== Changed

* Update document for errors ({pull-request-url}/11[#11])

== {compare-url}/v0.2.0\...v0.3.0[0.3.0] - 2024-04-07

=== Changed
Expand Down
37 changes: 37 additions & 0 deletions cmd/glzip/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: 2024 Shun Sakai
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

package main

import (
"flag"
"fmt"

"github.com/sorairolake/lzip-go"
)

const version = "0.3.1"

type options struct {
version bool
stdout bool
decompress bool
keep bool
dictionarySize uint
}

var opt options

func init() {
flag.BoolVar(&opt.version, "version", false, "Print version number")
flag.BoolVar(&opt.stdout, "stdout", false, "Write to standard output, keep input files")
flag.BoolVar(&opt.decompress, "decompress", false, "Decompress data")
flag.BoolVar(&opt.keep, "keep", false, "Keep input files")
flag.UintVar(&opt.dictionarySize, "dictionary-size", lzip.DefaultDictSize, "Set dictionary size in bytes")

flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: glzip [OPTIONS] <FILE>...\n")
flag.PrintDefaults()
}
}
55 changes: 55 additions & 0 deletions cmd/glzip/compress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: 2024 Shun Sakai
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

package main

import (
"bufio"
"io"
"os"

"github.com/sorairolake/lzip-go"
)

func compress(file string, output *os.File, opt options) error {
if !opt.stdout {
out, err := os.Create(file + ".lz")
if err != nil {
return err
}

output = out
}

defer output.Close()

writerOpt := &lzip.WriterOptions{DictSize: uint32(opt.dictionarySize)}

bufWriter := bufio.NewWriter(output)
defer bufWriter.Flush()

writer, err := lzip.NewWriterOptions(bufWriter, writerOpt)
if err != nil {
return err
}
defer writer.Close()

input, err := os.Open(file)
if err != nil {
return err
}
defer input.Close()

if _, err := io.Copy(writer, input); err != nil {
return err
}

if !opt.keep {
if err := os.Remove(file); err != nil {
return err
}
}

return nil
}
29 changes: 29 additions & 0 deletions cmd/glzip/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2024 Shun Sakai
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

// Glzip reduces the size of files. It reads and writes of lzip format
// compressed files.
//
// Usage:
//
// glzip [OPTIONS] <FILE>...
//
// Arguments:
//
// <FILE>
// Input file.
//
// Options:
//
// -stdout
// Write to standard output, keep input files.
// -decompress
// Decompress data.
// -keep
// Keep input files.
// -dictionary-size <BYTE>
// Set dictionary size in bytes.
// -version
// Print version number.
package main
111 changes: 2 additions & 109 deletions cmd/glzip/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,120 +5,13 @@
package main

import (
"bufio"
"flag"
"fmt"
"io"
"log"
"os"
"strings"

"github.com/sorairolake/lzip-go"
)

const version = "0.3.0"

type options struct {
version bool
stdout bool
decompress bool
keep bool
dictionarySize uint
}

func compress(file string, output *os.File, opt options) error {
if !opt.stdout {
out, err := os.Create(file + ".lz")
if err != nil {
return err
}

output = out
}

defer output.Close()

writerOpt := &lzip.WriterOptions{DictSize: uint32(opt.dictionarySize)}

bufWriter := bufio.NewWriter(output)
defer bufWriter.Flush()

writer, err := lzip.NewWriterOptions(bufWriter, writerOpt)
if err != nil {
return err
}
defer writer.Close()

input, err := os.Open(file)
if err != nil {
return err
}
defer input.Close()

if _, err := io.Copy(writer, input); err != nil {
return err
}

if !opt.keep {
if err := os.Remove(file); err != nil {
return err
}
}

return nil
}

func uncompress(file string, output *os.File, opt options) error {
input, err := os.Open(file)
if err != nil {
return err
}
defer input.Close()

bufReader := bufio.NewReader(input)

reader, err := lzip.NewReader(bufReader)
if err != nil {
return err
}

if !opt.stdout {
out, err := os.Create(strings.TrimSuffix(file, ".lz"))
if err != nil {
return err
}

output = out
}

defer output.Close()

if _, err := io.Copy(output, reader); err != nil {
return err
}

if !opt.keep {
if err := os.Remove(file); err != nil {
return err
}
}

return nil
}

func main() {
opt := new(options)

flag.BoolVar(&opt.version, "version", false, "Print version number")
flag.BoolVar(&opt.stdout, "stdout", false, "Write to standard output, keep input files")
flag.BoolVar(&opt.decompress, "decompress", false, "Decompress data")
flag.BoolVar(&opt.keep, "keep", false, "Keep input files")
flag.UintVar(&opt.dictionarySize, "dictionary-size", lzip.DefaultDictSize, "Set dictionary size in bytes")

flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: glzip [OPTIONS] <FILE>...\n")
flag.PrintDefaults()
}
flag.Parse()
args := flag.Args()

Expand All @@ -140,13 +33,13 @@ func main() {

if !opt.decompress {
for _, file := range args {
if err := compress(file, output, *opt); err != nil {
if err := compress(file, output, opt); err != nil {
log.Fatal(err)
}
}
} else {
for _, file := range args {
if err := uncompress(file, output, *opt); err != nil {
if err := uncompress(file, output, opt); err != nil {
log.Fatal(err)
}
}
Expand Down
52 changes: 52 additions & 0 deletions cmd/glzip/uncompress.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: 2024 Shun Sakai
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

package main

import (
"bufio"
"io"
"os"
"strings"

"github.com/sorairolake/lzip-go"
)

func uncompress(file string, output *os.File, opt options) error {
input, err := os.Open(file)
if err != nil {
return err
}
defer input.Close()

bufReader := bufio.NewReader(input)

reader, err := lzip.NewReader(bufReader)
if err != nil {
return err
}

if !opt.stdout {
out, err := os.Create(strings.TrimSuffix(file, ".lz"))
if err != nil {
return err
}

output = out
}

defer output.Close()

if _, err := io.Copy(output, reader); err != nil {
return err
}

if !opt.keep {
if err := os.Remove(file); err != nil {
return err
}
}

return nil
}
4 changes: 2 additions & 2 deletions docs/man/man1/glzip.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Specify in UTC.
:docdate: 2024-04-04
:doctype: manpage
:mansource: glzip 0.3.0
:mansource: glzip 0.3.1
:manmanual: General Commands Manual
:includedir: ../include

Expand Down Expand Up @@ -43,7 +43,7 @@ _FILE_::

Keep input files.

*-dictionary-size*::
*-dictionary-size* _BYTE_::

Set dictionary size in bytes.

Expand Down
Loading

0 comments on commit ff00296

Please sign in to comment.