Compare commits
11 Commits
feature/pw
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
5fc2672d64 | ||
|
b7af56dadf | ||
|
baeafa3ab5 | ||
|
bf5b250df8 | ||
|
3a636bfb4b | ||
|
65218af636 | ||
|
ece00da8dc | ||
|
7d6c06b251 | ||
|
a6d42ce5ca | ||
|
b8b468f0b8 | ||
|
d094be6014 |
18
README.md
18
README.md
@ -36,7 +36,7 @@ Utilities:
|
|||||||
* [ ] `fold`
|
* [ ] `fold`
|
||||||
* [ ] `getconf`
|
* [ ] `getconf`
|
||||||
* [ ] `grep`
|
* [ ] `grep`
|
||||||
* [ ] `head`
|
* [x] `head`
|
||||||
* [ ] `hostname`
|
* [ ] `hostname`
|
||||||
* [ ] `join`
|
* [ ] `join`
|
||||||
* [ ] `kill`
|
* [ ] `kill`
|
||||||
@ -45,7 +45,7 @@ Utilities:
|
|||||||
* [ ] `logger`
|
* [ ] `logger`
|
||||||
* [ ] `logname`
|
* [ ] `logname`
|
||||||
* [ ] `ls`
|
* [ ] `ls`
|
||||||
* [ ] `md5sum`
|
* [x] `md5sum`
|
||||||
* [ ] `mkdir`
|
* [ ] `mkdir`
|
||||||
* [ ] `mkfifo`
|
* [ ] `mkfifo`
|
||||||
* [ ] `mktemp`
|
* [ ] `mktemp`
|
||||||
@ -67,13 +67,13 @@ Utilities:
|
|||||||
* [ ] `sed`
|
* [ ] `sed`
|
||||||
* [ ] `seq`
|
* [ ] `seq`
|
||||||
* [ ] `setsid`
|
* [ ] `setsid`
|
||||||
* [ ] `sha1sum`
|
* [x] `sha1sum`
|
||||||
* [ ] `sha224sum`
|
* [x] `sha224sum`
|
||||||
* [ ] `sha256sum`
|
* [x] `sha256sum`
|
||||||
* [ ] `sha384sum`
|
* [x] `sha384sum`
|
||||||
* [ ] `sha512-224sum`
|
* [x] `sha512-224sum`
|
||||||
* [ ] `sha512-256sum`
|
* [x] `sha512-256sum`
|
||||||
* [ ] `sha512sum`
|
* [x] `sha512sum`
|
||||||
* [ ] `sleep`
|
* [ ] `sleep`
|
||||||
* [ ] `sort`
|
* [ ] `sort`
|
||||||
* [ ] `split`
|
* [ ] `split`
|
||||||
|
17
error.go
Normal file
17
error.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package coreutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PrintToStderr(v interface{}) {
|
||||||
|
fmt.Fprintf(os.Stderr, "%v: %v\n", os.Args[0], v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExitIfError(err error) {
|
||||||
|
if err != nil {
|
||||||
|
PrintToStderr(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
5
go.mod
5
go.mod
@ -1,3 +1,6 @@
|
|||||||
module source.heropunch.io/tomo/go-coreutils
|
module source.heropunch.io/tomo/go-coreutils
|
||||||
|
|
||||||
require github.com/stretchr/testify v1.3.0
|
require (
|
||||||
|
github.com/alexflint/go-arg v1.0.0
|
||||||
|
github.com/stretchr/testify v1.3.0
|
||||||
|
)
|
||||||
|
10
go.sum
10
go.sum
@ -1,7 +1,17 @@
|
|||||||
|
github.com/alexflint/go-arg v1.0.0 h1:VWNnY3DyBHiq5lcwY2FlCE5t5qyHNV0o5i1bkCIHprU=
|
||||||
|
github.com/alexflint/go-arg v1.0.0/go.mod h1:Cto8k5VtkP4pp0EXiWD4ZJMFOOinZ38ggVcQ/6CGuRI=
|
||||||
|
github.com/alexflint/go-scalar v1.0.0 h1:NGupf1XV/Xb04wXskDFzS0KWOLH632W/EO4fAFi+A70=
|
||||||
|
github.com/alexflint/go-scalar v1.0.0/go.mod h1:GpHzbCOZXEKMEcygYQ5n/aa4Aq84zbxjy3MxYW0gjYw=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
240
hashsum.go
Normal file
240
hashsum.go
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
package coreutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/sha1"
|
||||||
|
"crypto/sha256"
|
||||||
|
"crypto/sha512"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"hash"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/alexflint/go-arg"
|
||||||
|
)
|
||||||
|
|
||||||
|
var MD5Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{32}) (?P<filename>.*)$")
|
||||||
|
var SHA1Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{40}) (?P<filename>.*)$")
|
||||||
|
var SHA224Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{56}) (?P<filename>.*)$")
|
||||||
|
var SHA256Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{64}) (?P<filename>.*)$")
|
||||||
|
var SHA384Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{96}) (?P<filename>.*)$")
|
||||||
|
var SHA512Regex = regexp.MustCompile("^(?P<hash>[0-9a-f]{128}) (?P<filename>.*)$")
|
||||||
|
var SHA512_224Regex = SHA224Regex
|
||||||
|
var SHA512_256Regex = SHA256Regex
|
||||||
|
|
||||||
|
// SumFunc is a type of function that computes a hash.Hash for data in io.Reader
|
||||||
|
type SumFunc func(io.Reader) (hash.Hash, error)
|
||||||
|
|
||||||
|
func copyIntoHash(r io.Reader, h hash.Hash) (hash.Hash, error) {
|
||||||
|
if _, err := io.Copy(h, r); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return h, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func MD5Sum(r io.Reader) (hash.Hash, error) {
|
||||||
|
return copyIntoHash(r, md5.New())
|
||||||
|
}
|
||||||
|
|
||||||
|
func SHA1Sum(r io.Reader) (hash.Hash, error) {
|
||||||
|
return copyIntoHash(r, sha1.New())
|
||||||
|
}
|
||||||
|
|
||||||
|
func SHA224Sum(r io.Reader) (hash.Hash, error) {
|
||||||
|
return copyIntoHash(r, sha256.New224())
|
||||||
|
}
|
||||||
|
|
||||||
|
func SHA256Sum(r io.Reader) (hash.Hash, error) {
|
||||||
|
return copyIntoHash(r, sha256.New())
|
||||||
|
}
|
||||||
|
|
||||||
|
func SHA384Sum(r io.Reader) (hash.Hash, error) {
|
||||||
|
return copyIntoHash(r, sha512.New384())
|
||||||
|
}
|
||||||
|
|
||||||
|
func SHA512Sum(r io.Reader) (hash.Hash, error) {
|
||||||
|
return copyIntoHash(r, sha512.New())
|
||||||
|
}
|
||||||
|
|
||||||
|
func SHA512_224Sum(r io.Reader) (hash.Hash, error) {
|
||||||
|
return copyIntoHash(r, sha512.New512_224())
|
||||||
|
}
|
||||||
|
|
||||||
|
func SHA512_256Sum(r io.Reader) (hash.Hash, error) {
|
||||||
|
return copyIntoHash(r, sha512.New512_256())
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckingResults struct {
|
||||||
|
ImproperlyFormattedCount uint
|
||||||
|
InvalidChecksumCount uint
|
||||||
|
FilesNotRead uint
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImproperlyFormattedErr is an error return when a line for checking
|
||||||
|
// has an incorrect number or set of characters
|
||||||
|
var ImproperlyFormattedErr = errors.New("improperly formatted line")
|
||||||
|
|
||||||
|
func printHash(h hash.Hash, filename string) {
|
||||||
|
fmt.Printf("%x %v\n", h.Sum(nil), filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrintSumForFile prints checksum computed by f for file with filename
|
||||||
|
func PrintSumForFile(filename string, f SumFunc) error {
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
h, err := f(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printHash(h, filename)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrintSumForStdin prints checksum computed by f for data from stdin
|
||||||
|
func PrintSumForStdin(f SumFunc) {
|
||||||
|
h, err := f(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
|
PrintToStderr(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
printHash(h, "<stdin>")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkLine(line string, re *regexp.Regexp, f SumFunc) (valid bool, err error) {
|
||||||
|
matches := re.MatchString(line)
|
||||||
|
if !matches {
|
||||||
|
err = ImproperlyFormattedErr
|
||||||
|
valid = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
submatches := re.FindStringSubmatch(line)
|
||||||
|
hash := submatches[1]
|
||||||
|
filename := submatches[2]
|
||||||
|
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
valid = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
h, err := f(file)
|
||||||
|
if err != nil {
|
||||||
|
valid = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result := "OK"
|
||||||
|
valid = true
|
||||||
|
if fmt.Sprintf("%x", h.Sum(nil)) != hash {
|
||||||
|
result = "FAILED"
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
fmt.Printf("%s: %s\n", filename, result)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckSumsInReader checks checksums in r using f
|
||||||
|
func CheckSumsInReader(r io.Reader, re *regexp.Regexp, f SumFunc) (*CheckingResults, error) {
|
||||||
|
scanner := bufio.NewScanner(r)
|
||||||
|
|
||||||
|
results := CheckingResults{}
|
||||||
|
for scanner.Scan() {
|
||||||
|
valid, err := checkLine(scanner.Text(), re, f)
|
||||||
|
if err == ImproperlyFormattedErr {
|
||||||
|
results.ImproperlyFormattedCount++
|
||||||
|
} else if err != nil {
|
||||||
|
PrintToStderr(err)
|
||||||
|
results.FilesNotRead++
|
||||||
|
} else if !valid {
|
||||||
|
results.InvalidChecksumCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &results, scanner.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckSumsInFile checks checksums in file with filename using f
|
||||||
|
func CheckSumsInFile(filename string, re *regexp.Regexp, f SumFunc) (*CheckingResults, error) {
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
return CheckSumsInReader(file, re, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrintCheckingResults prints the number of mismatched checksums and improperly formatted lines to os.Stderr
|
||||||
|
func PrintCheckingResults(results CheckingResults) {
|
||||||
|
if results.InvalidChecksumCount > 0 {
|
||||||
|
PrintToStderr(
|
||||||
|
fmt.Sprintf("%v computed checksums did NOT match", results.InvalidChecksumCount),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if results.ImproperlyFormattedCount > 0 {
|
||||||
|
PrintToStderr(
|
||||||
|
fmt.Sprintf("%v lines are improperly formatted", results.ImproperlyFormattedCount),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if results.FilesNotRead > 0 {
|
||||||
|
PrintToStderr(
|
||||||
|
fmt.Sprintf("%v listed files could not be read", results.FilesNotRead),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SumMain is a function you're supposed to run in main of a hash sum utility
|
||||||
|
func SumMain(re *regexp.Regexp, f SumFunc) {
|
||||||
|
var args struct {
|
||||||
|
Check bool `arg:"-c"`
|
||||||
|
Files []string `arg:"positional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
arg.MustParse(&args)
|
||||||
|
|
||||||
|
exitCode := 0
|
||||||
|
if len(args.Files) == 0 {
|
||||||
|
if !args.Check {
|
||||||
|
PrintSumForStdin(f)
|
||||||
|
} else {
|
||||||
|
results, err := CheckSumsInReader(os.Stdin, re, f)
|
||||||
|
if err != nil {
|
||||||
|
PrintToStderr(err)
|
||||||
|
exitCode = 1
|
||||||
|
}
|
||||||
|
PrintCheckingResults(*results)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
totalResults := CheckingResults{}
|
||||||
|
for _, filename := range args.Files {
|
||||||
|
if !args.Check {
|
||||||
|
err := PrintSumForFile(filename, f)
|
||||||
|
if err != nil {
|
||||||
|
PrintToStderr(err)
|
||||||
|
exitCode = 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
results, err := CheckSumsInFile(filename, re, f)
|
||||||
|
if err != nil {
|
||||||
|
PrintToStderr(err)
|
||||||
|
exitCode = 1
|
||||||
|
}
|
||||||
|
if results != nil {
|
||||||
|
totalResults.ImproperlyFormattedCount += results.ImproperlyFormattedCount
|
||||||
|
totalResults.InvalidChecksumCount += results.InvalidChecksumCount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PrintCheckingResults(totalResults)
|
||||||
|
os.Exit(exitCode)
|
||||||
|
}
|
69
hashsum_test.go
Normal file
69
hashsum_test.go
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package coreutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CheckLineTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *CheckLineTestSuite) TestImproperlyFormattedLine() {
|
||||||
|
t := suite.T()
|
||||||
|
valid, err := checkLine("name chef", MD5Regex, MD5Sum)
|
||||||
|
assert.Equal(t, false, valid)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, ImproperlyFormattedErr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *CheckLineTestSuite) TestMismatchedChecksum() {
|
||||||
|
t := suite.T()
|
||||||
|
line := "4a5fb9ebd6c8ea7efb53d071053ef778 " + path.Join("test_data", "some_file.txt")
|
||||||
|
valid, err := checkLine(line, MD5Regex, MD5Sum)
|
||||||
|
assert.Equal(t, false, valid)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *CheckLineTestSuite) TestValid() {
|
||||||
|
t := suite.T()
|
||||||
|
line := "6a5fb9ebd6c8ea7efb53d071053ef778 " + path.Join("test_data", "some_file.txt")
|
||||||
|
valid, err := checkLine(line, MD5Regex, MD5Sum)
|
||||||
|
assert.Equal(t, true, valid)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCheckLineTestSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(CheckLineTestSuite))
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckSumsInReaderTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *CheckSumsInReaderTestSuite) Test() {
|
||||||
|
t := suite.T()
|
||||||
|
buf := bytes.NewBufferString(strings.Join(
|
||||||
|
[]string{
|
||||||
|
"name chef",
|
||||||
|
"4a5fb9ebd6c8ea7efb53d071053ef778 " + path.Join("test_data", "some_file.txt"),
|
||||||
|
"6a5fb9ebd6c8ea7efb53d071053ef778 " + path.Join("test_data", "some_file.txt"),
|
||||||
|
"4a5fb9ebd6c8ea7efb53d071053ef778 nonexistant_file",
|
||||||
|
},
|
||||||
|
"\n",
|
||||||
|
))
|
||||||
|
results, err := CheckSumsInReader(buf, MD5Regex, MD5Sum)
|
||||||
|
assert.NotNil(t, results)
|
||||||
|
assert.Equal(t, uint(1), results.ImproperlyFormattedCount)
|
||||||
|
assert.Equal(t, uint(1), results.FilesNotRead)
|
||||||
|
assert.Equal(t, uint(1), results.InvalidChecksumCount)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCheckSumsInReaderTestSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(CheckSumsInReaderTestSuite))
|
||||||
|
}
|
43
head/head.go
Normal file
43
head/head.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/alexflint/go-arg"
|
||||||
|
common "source.heropunch.io/tomo/go-coreutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func head(num uint, reader io.Reader) {
|
||||||
|
scanner := bufio.NewScanner(reader)
|
||||||
|
for scanner.Scan() && num > 0 {
|
||||||
|
fmt.Println(scanner.Text())
|
||||||
|
num = num - 1
|
||||||
|
}
|
||||||
|
common.ExitIfError(scanner.Err())
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var args struct {
|
||||||
|
Lines uint `arg:"-n"`
|
||||||
|
Files []string `arg:"positional"`
|
||||||
|
}
|
||||||
|
args.Lines = 10
|
||||||
|
arg.MustParse(&args)
|
||||||
|
|
||||||
|
if len(args.Files) == 0 {
|
||||||
|
head(args.Lines, os.Stdin)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
for _, filename := range args.Files {
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
common.ExitIfError(err)
|
||||||
|
|
||||||
|
head(args.Lines, file)
|
||||||
|
|
||||||
|
err = file.Close()
|
||||||
|
common.ExitIfError(err)
|
||||||
|
}
|
||||||
|
}
|
9
md5sum/md5sum.go
Normal file
9
md5sum/md5sum.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
common "source.heropunch.io/tomo/go-coreutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
common.SumMain(common.MD5Regex, common.MD5Sum)
|
||||||
|
}
|
9
sha1sum/sha1sum.go
Normal file
9
sha1sum/sha1sum.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
common "source.heropunch.io/tomo/go-coreutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
common.SumMain(common.SHA1Regex, common.SHA1Sum)
|
||||||
|
}
|
9
sha224sum/sha224sum.go
Normal file
9
sha224sum/sha224sum.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
common "source.heropunch.io/tomo/go-coreutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
common.SumMain(common.SHA224Regex, common.SHA224Sum)
|
||||||
|
}
|
9
sha256sum/sha256sum.go
Normal file
9
sha256sum/sha256sum.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
common "source.heropunch.io/tomo/go-coreutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
common.SumMain(common.SHA256Regex, common.SHA256Sum)
|
||||||
|
}
|
9
sha384sum/sha384sum.go
Normal file
9
sha384sum/sha384sum.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
common "source.heropunch.io/tomo/go-coreutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
common.SumMain(common.SHA384Regex, common.SHA384Sum)
|
||||||
|
}
|
9
sha512-224sum/sha512-224sum.go
Normal file
9
sha512-224sum/sha512-224sum.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
common "source.heropunch.io/tomo/go-coreutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
common.SumMain(common.SHA512_224Regex, common.SHA512_224Sum)
|
||||||
|
}
|
9
sha512-256sum/sha512-256sum.go
Normal file
9
sha512-256sum/sha512-256sum.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
common "source.heropunch.io/tomo/go-coreutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
common.SumMain(common.SHA512_256Regex, common.SHA512_256Sum)
|
||||||
|
}
|
9
sha512sum/sha512sum.go
Normal file
9
sha512sum/sha512sum.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
common "source.heropunch.io/tomo/go-coreutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
common.SumMain(common.SHA512Regex, common.SHA512Sum)
|
||||||
|
}
|
1
test_data/some_file.txt
Normal file
1
test_data/some_file.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
blah blah
|
Loading…
Reference in New Issue
Block a user