-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the -checksum flag to calculate and print the checksum for source…
… file
- Loading branch information
Showing
9 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package checksum | ||
|
||
import ( | ||
"github.com/no-src/gofs/util/hashutil" | ||
"github.com/no-src/gofs/util/jsonutil" | ||
"github.com/no-src/log" | ||
) | ||
|
||
// PrintChecksum calculate and print the checksum for file | ||
func PrintChecksum(path string, chunkSize int64, checkpointCount int) error { | ||
hvs, err := hashutil.CheckpointsMD5FromFileName(path, chunkSize, checkpointCount) | ||
if err != nil { | ||
log.Error(err, "calculate file checksum error") | ||
return err | ||
} | ||
|
||
hvsJson, _ := jsonutil.MarshalIndent(hvs) | ||
log.Log(string(hvsJson)) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package checksum | ||
|
||
import "testing" | ||
|
||
func TestPrintChecksum(t *testing.T) { | ||
path := "./checksum_test.go" | ||
err := PrintChecksum(path, 1024*1024, 10) | ||
if err != nil { | ||
t.Errorf("test PrintChecksum error => %v", err) | ||
} | ||
} | ||
|
||
func TestPrintChecksumError(t *testing.T) { | ||
path := "./" | ||
err := PrintChecksum(path, 1024*1024, 10) | ||
if err == nil { | ||
t.Errorf("test PrintChecksum expect get error but get nil") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters