No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Humphrey Drummond 1476a58968 Migrate module path from github.com to codeberg.org
Codeberg is the primary source; GitHub is a mirror.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 23:01:59 +00:00
.vscode Release v0.1.0 - First release 2026-02-24 19:52:31 +00:00
CHANGELOG.md Initial release: HashFile, HashReader, HashBytes 2026-02-24 19:20:29 +00:00
go.mod Migrate module path from github.com to codeberg.org 2026-03-26 23:01:59 +00:00
hash.go Initial release: HashFile, HashReader, HashBytes 2026-02-24 19:20:29 +00:00
hash_test.go Initial release: HashFile, HashReader, HashBytes 2026-02-24 19:20:29 +00:00
README.md Migrate module path from github.com to codeberg.org 2026-03-26 23:01:59 +00:00
task-plus.yml Add task-plus.yml and links section to README 2026-03-09 16:25:05 +00:00
Taskfile.yml Release v0.1.0 - First release 2026-02-24 19:52:31 +00:00

godocs-hash

Compute document hashes compatible with godocs.

External tools can use this library to pre-check whether a document already exists before uploading.

Algorithm

MD5 of the raw file bytes, formatted as 32-character lowercase hex.

Install

go get github.com/drummonds/godocs-hash

Usage

import godocshash "github.com/drummonds/godocs-hash"

hash, err := godocshash.HashFile("invoice.pdf")
// Check: GET https://your-godocs/api/document/lookup?hash=<hash>
// 200 → already exists, skip upload
// 404 → upload via POST /api/document/upload

Three functions are provided:

  • HashFile(path) — hash a file by path
  • HashReader(r) — hash from any io.Reader
  • HashBytes(data) — hash in-memory bytes

Shell equivalent

md5sum invoice.pdf | cut -d' ' -f1

Python equivalent

import hashlib
hashlib.md5(open("invoice.pdf", "rb").read()).hexdigest()
Documentation https://h3-godocs-hash.statichost.page/
Source (Codeberg) https://codeberg.org/hum3/godocs-hash
Mirror (GitHub) https://github.com/drummonds/godocs-hash