hash/defrag: support the blake3 algorithm - #202
Merged
Conversation
blake3 is not part of hashlib, so it comes from the optional "blake3" package: pip install 'borgstore[blake3]'. The new borgstore.utils.hashing module wraps hashlib and adds blake3 for hashing purposes, so all the backends (and the REST server) support it in hash and defrag. For backends computing hashes remotely, the package needs to be installed on the server side. sftp always computes blake3 client-side, because the SFTP "check-file" extension does not support blake3 (and asking for it would make us give up on check-file for all later calls). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds "blake3" as an alternative to the hashlib algorithms for
Store.hash/backend.hashand for the content-hash target names computed bydefrag.blake3 is not part of hashlib, so it comes from the optional
blake3package:pip install 'borgstore[blake3]'Implementation
borgstore.utils.hashingmodule:new(algorithm, data=b"")andfile_digest(fileobj, algorithm)- hashlib for everything else, the blake3package for
"blake3".If the package is not installed, this raises the usual
ValueError: Unsupported hash algorithm: blake3 (pip install 'borgstore[blake3]'),so callers do not need any new error handling.
_base.BackendBase.hashand.defraguse it, which covers rclone, s3 and theREST server side.
file_digestpath (no full read into memory)for blake3, too.
check-fileattempt for blake3: the extension onlydefines md5/sha*, and a failed attempt would permanently set
check_file_supported = False, disabling server-side sha256 hashing for therest of the connection.
but the
blake3package must be installed on the server for server-sidehash/defrag computations.
Nesting is unaffected: a blake3 hexdigest is 64 hex chars, same as sha256.
Tests
New
tests/test_hashing.pyplus blake3 cases for backend hash, Store hash,Store defrag, REST server hash and REST backend defrag. All are
skipif-guarded,so the test suite passes with and without the blake3 package installed
(verified both ways). tox/CI now install the
blake3extra.