sumdiff

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

README

sumdiff

Compare sdk/tools for directory and files.

Features

  • Support comparing files or directories result is equals.
  • Supports comparing files or directories with the difference list.
  • Support for calculating the hash of a file or directories md5/sha1/sha256/sha512.
  • This library supports both SDK and CLI tools.
  • CLI support result format : table/json/csv/yaml
  • CLI support result output to a file.

SDK

Install

go get -u github.com/foolin/sumdiff

API


//Compare 
ok, result, err := sumdiff.Cmp(path1, path2)

//Equal
ok, err := sumdiff.Equal(v.path1, v.path2)

CLI Tool

sumdiff  --help

A useful comparison tool for differences and hash

Usage:
  sumdiff [command]

Available Commands:
  cmp         Compare the two files or directories are different
  completion  Generate the autocompletion script for the specified shell
  eq          Compare whether two files or directory are equal
  hash        Calculate hash algorithm [md5|sha1|sha256|sha512] hex string
  help        Help about any command
  md5         Calculate md5 hex string
  sha1        Calculate sha1 hex string
  sha256      Calculate sha256 hex string

Flags:
  -f, --format string   Format: table|json|csv|yaml (default "table")
  -h, --help            help for sumdiff
  -o, --output string   Output filename
  -v, --verbose         Verbose output info

Use "sumdiff [command] --help" for more information about a command.


Usage

sumdiff eq - Compare equal
  • Compare the two files or directories are equal sumdiff eq <path1> <path2>

    Example1:

    sumdiff eq test_data/a.txt test_data/b.txt 
    

    Output1:

    +--------+                                                                                          
    | result |
    +--------+
    |  true  |
    +--------+
    

    Example2:

    sumdiff eq test_data/c.txt test_data/d.txt 
    

    Output2:

    false
    
sumdiff cmp - Compare different true or false
  • Compare the two file or directory differences sumdiff diff <path1> <path2>

Example:

sumdiff cmp test_data/data1 test_data/data3

Output:

+-------------------------------------------+                                                       
| Path   | OK    | Msg                      |
+-------------------------------------------+
|        | true  |                          |
| /a.txt | true  |                          |
| /b.txt | true  |                          |
| /c.txt | false | path1 not exist [/c.txt] |
+-------------------------------------------+
false
sumdiff md5 - Get MD5 hash value

Calculate the MD5 hexadecimal value of the files or directories sumdiff md5 <path1> [<path2>] [<path3>] ...

Example:

sumdiff md5 test_data/a.txt

Output:

+-----------------------------------------------------------+                                       
| Hash                             | Size | Path            |
+-----------------------------------------------------------+
| 9d15fa011b54dbd079d1d20e36e4a358 | 212  | test_data/a.txt |
+-----------------------------------------------------------+
sumdiff sha1 - Get SHA1 hash value

Calculate the MD5 hexadecimal value of the files or directories sumdiff sha1 <path1> [<path2>] [<path3>] ...

Example:

sumdiff sha1 test_data/data1

Output:

+---------------------------------------------------------------+                                   
| Hash                                     | Size | Path        |
+---------------------------------------------------------------+
| 18b012c3e30bf822589ac96fd4d87e6e8d89754e | 4096 | data1/a.txt |
| 9c678f3b44c0918f5695e5a0a8232ab1b017a4a4 | 4096 | data1/b.txt |
+---------------------------------------------------------------+
sumdiff sha256 - Get SHA256 hash value

sumdiff sha256 <path1> [<path2>] [<path3>] ...

Example:

sumdiff sha256 test_data/a.txt test_data/c.txt

Output:

+-------------------------------------------------------------------------------------------+       
| Hash                                                             | Size | Path            |
+-------------------------------------------------------------------------------------------+
| bb3cf386d0c975847024b0d78c9f92c0657c894f16c1db1248233cfe2b05b65f | 212  | test_data/a.txt |
| 732d2d9a2c39480fa38bd060f07b3e55eb3b47888e8019a8d4cfd8600d5c104f | 222  | test_data/c.txt |
+-------------------------------------------------------------------------------------------+
sumdiff hash - Get Other hash value

Calculate the hash(md5|sha1|sha256|sha512) value of a file or directory sumdiff hash <md5|sha1|sha256|sha512> <path1> [<path2>] [<path3>] ...

Example:

sumdiff hash sha512 test_data/a.txt

Output:

+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Hash                                                                                                                             | Size | Path            |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| 9683aedddcc5b16548f3510580d91306fad405070fd516299e3f5609bff5fd950a1a6e39e8bce5000d4f3c264428855eb2ae0f235f55d89bd9ec2c9f02c86c4b | 212  | test_data/a.txt |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+

Help

sumdiff -h

Install

linux:


tar -xvf sumdiff_Linux_x86_64.tar.gz && sudo mv sumdiff /usr/local/bin

Documentation

Overview

Copyright © 2023 Foolin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cmp

func Cmp(path1, path2 string) (ok bool, res vo.CmpList, err error)

func CmpDir

func CmpDir(path1, path2 string) (bool, vo.CmpList, error)

func CmpFile

func CmpFile(file1, file2 string) (bool, vo.CmpInfo, error)

func Equal

func Equal(path1, path2 string) (ok bool, err error)

func EqualDir

func EqualDir(path1, path2 string) (bool, error)

func EqualFile

func EqualFile(file1, file2 string) (bool, error)

func Hash

func Hash(h hash.Hash, paths ...string) (list vo.HashList, err error)

func HashWithArgs

func HashWithArgs(args ...string) (list vo.HashList, err error)

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL