check(self,
hash_algorithm,
offset=0,
length=0,
block_size=0)
| source code
|
Ask the server for a hash of a section of this file. This can be used
to verify a successful upload or download, or for various rsync-like
operations.
The file is hashed from offset , for length
bytes. If length is 0, the remainder of the file is hashed.
Thus, if both offset and length are zero, the
entire file is hashed.
Normally, block_size will be 0 (the default), and this
method will return a byte string representing the requested hash (for
example, a string of length 16 for MD5, or 20 for SHA-1). If a non-zero
block_size is given, each chunk of the file (from
offset to offset + length ) of
block_size bytes is computed as a separate hash. The hash
results are all concatenated and returned as a single string.
For example, check('sha1', 0, 1024, 512) will return a
string of length 40. The first 20 bytes will be the SHA-1 of the first
512 bytes of the file, and the last 20 bytes will be the SHA-1 of the
next 512 bytes.
- Parameters:
hash_algorithm (str) - the name of the hash algorithm to use (normally
"sha1" or "md5" )
offset (int or long) - offset into the file to begin hashing (0 means to start from the
beginning)
length (int or long) - number of bytes to hash (0 means continue to the end of the file)
block_size (int) - number of bytes to hash per result (must not be less than 256; 0
means to compute only one hash of the entire segment)
- Returns: str
- string of bytes representing the hash of each block, concatenated
together
- Raises:
IOError - if the server doesn't support the "check-file" extension,
or possibly doesn't support the hash algorithm requested
Note:
Many (most?) servers don't support this extension yet.
Since:
1.4
|