"os"
"path"
"strings"
+ "time"
meta4ra "go.stargrave.org/meta4ra/internal"
)
func runCheck() {
pipe := flag.Bool("pipe", false, "Verify file data from stdin, copy to stdout")
+ progress := flag.Bool("progress", false, "Show progress of piping/downloading")
allHashes := flag.Bool("all-hashes", false, "Check all hashes, not the first common one")
hashes := flag.String("hashes", meta4ra.HashesDefault,
"hash-name:commandline[,...]")
} else {
w = hasher
}
+ if *progress {
+ bar := Progress{w: w, now: time.Now(), total: f.Size}
+ bar.next = bar.now.Add(ProgressPeriod)
+ w = &bar
+ }
_, err = io.Copy(w, bufio.NewReaderSize(src, meta4ra.BufLen))
if !*pipe || *dl != -1 {
src.Close()
--- /dev/null
+// meta4ra -- Metalink 4.0 utilities
+// Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package main
+
+import (
+ "fmt"
+ "io"
+ "os"
+ "time"
+
+ "github.com/dustin/go-humanize"
+)
+
+var ProgressPeriod = time.Second
+
+type Progress struct {
+ now, next time.Time
+ wrote, total uint64
+ w io.Writer
+}
+
+func (p *Progress) Write(data []byte) (n int, err error) {
+ n, err = p.w.Write(data)
+ p.wrote += uint64(len(data))
+ p.now = time.Now()
+ if p.now.After(p.next) {
+ p.next = p.now.Add(ProgressPeriod)
+ fmt.Fprintf(os.Stderr, "%d%% | %s / %s\n",
+ int(100*p.wrote/p.total),
+ humanize.IBytes(p.wrote),
+ humanize.IBytes(p.total))
+ }
+ return
+}
)
require (
+ github.com/dustin/go-humanize v1.0.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
golang.org/x/sys v0.22.0 // indirect
)
github.com/dchest/skein v0.0.0-20171112102903-d7f1022db390 h1:oNcAGoFeaPCgOnlARnJMQqgoq1UMlGwW7PFJddtTF2c=
github.com/dchest/skein v0.0.0-20171112102903-d7f1022db390/go.mod h1:sh8l6PI4IHMaBmo2rlnHxnJDjXY7rxmDeaGSyupxMVM=
+github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
+github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
)
const (
- Generator = "meta4ra/0.9.1"
+ Generator = "meta4ra/0.10.0"
SigMediaTypePGP = "application/pgp-signature"
SigMediaTypeSSH = "application/ssh-signature"
BufLen = 1 << 20