-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
50 lines (41 loc) · 943 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/application-research/fastcommp"
)
func main() {
// Get the file name from the command-line arguments
if len(os.Args) != 2 {
fmt.Printf("Usage: %s <filename>\n", os.Args[0])
return
}
fileName := os.Args[1]
start := time.Now()
data, err := ioutil.ReadFile(fileName)
if err != nil {
fmt.Println("Error reading file:", err)
return
}
elapsed := time.Since(start)
fmt.Printf("Elapsed file read time: %s\n", elapsed)
fast := new(fastcommp.CommpWriter)
start = time.Now()
fast.Write(data)
sum, err := fast.Sum()
if err != nil {
panic(err)
}
elapsed = time.Since(start)
fmt.Printf("Elapsed commP time: %s\n", elapsed)
fmt.Printf("commP: %s\n", sum.PieceCID.String())
// Convert the sum results to a JSON string
results, err := json.MarshalIndent(sum, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(results))
}