Skip to content

Commit 414e608

Browse files
authored
Merge pull request #21 from boyter/ed2k
Ed2k hash support
2 parents 96db27d + 4489119 commit 414e608

16 files changed

Lines changed: 417 additions & 11 deletions

File tree

assets/db/migrations.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ create table if not exists file_hashes (
1616
sha3_256 text,
1717
sha3_384 text,
1818
sha3_512 text,
19+
ed2k text,
1920
size integer not null
2021
);

assets/db/queries.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
-- name: FileHashInsertReplace :one
44
insert or replace into file_hashes (
55
filepath, crc32, xxhash64, md4, md5, sha1, sha256, sha512,
6-
blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512,
6+
blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k,
77
size
8-
) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
8+
) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
99
returning *;
1010

1111
-- name: FileHashByFilePath :one

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
1010
github.com/spf13/cobra v1.8.1
1111
github.com/zeebo/blake3 v0.2.3
12+
go.felesatra.moe/hash/ed2k v1.0.2
1213
golang.org/x/crypto v0.31.0
1314
modernc.org/sqlite v1.40.1
1415
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ github.com/zeebo/blake3 v0.2.3 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg=
3737
github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvvKCaQ=
3838
github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo=
3939
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
40+
go.felesatra.moe/hash/ed2k v1.0.2 h1:veuWruebB5r8WCsQUyTbTFhVqlrGI58LlwH0G+JCBp0=
41+
go.felesatra.moe/hash/ed2k v1.0.2/go.mod h1:iJcvQPdpma+fJfAHbrIFPjT6UYEN6GFsgkm+SB+QHdY=
4042
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
4143
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
4244
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=

processor/database/db.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/database/models.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/database/queries.sql.go

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/formatters.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ func toSum(input chan Result) string {
130130
if hasHash(HashNames.Sha3512) {
131131
str.WriteString(res.Sha3512 + " " + res.File + "\n")
132132
}
133+
if hasHash(HashNames.Ed2k) {
134+
str.WriteString(res.Ed2k + " " + res.File + "\n")
135+
}
133136

134137
if !NoStream && FileOutput == "" {
135138
fmt.Print(str.String())
@@ -187,6 +190,9 @@ func toHashOnly(input chan Result) (string, bool) {
187190
if hasHash(HashNames.Sha3512) {
188191
str.WriteString(res.Sha3512 + "\n")
189192
}
193+
if hasHash(HashNames.Ed2k) {
194+
str.WriteString(res.Ed2k + "\n")
195+
}
190196

191197
if !NoStream && FileOutput == "" {
192198
fmt.Print(str.String())
@@ -253,6 +259,9 @@ func toText(input chan Result) (string, bool) {
253259
if hasHash(HashNames.Sha3512) {
254260
str.WriteString(" SHA3-512 " + res.Sha3512 + "\n")
255261
}
262+
if hasHash(HashNames.Ed2k) {
263+
str.WriteString(" ed2k " + res.Ed2k + "\n")
264+
}
256265

257266
if !NoStream && FileOutput == "" {
258267
fmt.Print(str.String())
@@ -371,6 +380,7 @@ func toSqlite(input chan Result) (string, bool) {
371380
Sha3256: toSqlNull(res.Sha3256),
372381
Sha3384: toSqlNull(res.Sha3384),
373382
Sha3512: toSqlNull(res.Sha3512),
383+
Ed2k: toSqlNull(res.Ed2k),
374384
Size: res.Bytes,
375385
})
376386
if err != nil {
@@ -427,6 +437,7 @@ func printHashes() {
427437
fmt.Printf(" SHA3-256 (%s)\n", HashNames.Sha3256)
428438
fmt.Printf(" SHA3-384 (%s)\n", HashNames.Sha3384)
429439
fmt.Printf(" SHA3-512 (%s)\n", HashNames.Sha3512)
440+
fmt.Printf(" ed2k (%s)\n", HashNames.Ed2k)
430441
}
431442

432443
func contains(list []string, v string) bool {

processor/processor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ var HashNames = Result{
8989
Sha3256: "sha3256",
9090
Sha3384: "sha3384",
9191
Sha3512: "sha3512",
92+
Ed2k: "ed2k",
9293
}
9394

9495
// Process is the main entry point of the command line it sets everything up and starts running
@@ -107,13 +108,13 @@ func Process() {
107108
}
108109
}
109110

110-
// If nothing was supplied as an argument to run against assume run against everything in the
111+
// If nothing was supplied as an argument to run against, assume run against everything in the
111112
// current directory recursively
112113
if len(DirFilePaths) == 0 {
113114
DirFilePaths = append(DirFilePaths, ".")
114115
}
115116

116-
// If a single argument is supplied enable recursive as if its a file no problem
117+
// If a single argument is supplied, enable recursive as if it's a file no problem
117118
// but if its a directory the user probably wants to hash everything in that directory
118119
if len(DirFilePaths) == 1 {
119120
Recursive = true

processor/structs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Result struct {
2121
Sha3256 string `json:",omitempty"`
2222
Sha3384 string `json:",omitempty"`
2323
Sha3512 string `json:",omitempty"`
24+
Ed2k string `json:"ed2k,omitempty"`
2425
Bytes int64
2526
MTime *time.Time `json:",omitzero"`
2627
}

0 commit comments

Comments
 (0)