class documentation

class HashWriter(BinaryIO):

Constructor: HashWriter(f, hash_func)

View In Hierarchy

Wrapper for file-like object that computes hash of its data.

This is a generic version that works with any hash algorithm.

Method __enter__ Enter context manager.
Method __exit__ Exit context manager and close file.
Method __init__ Initialize HashWriter.
Method __iter__ Return iterator.
Method __next__ Not supported for write-only file.
Method close Close the pack file and finalize the hash.
Method fileno Return file descriptor number.
Method flush Flush the file buffer.
Method isatty Check if file is a terminal.
Method offset Get the total number of bytes written.
Method read Not supported for write-only file.
Method readable Check if file is readable.
Method readline Not supported for write-only file.
Method readlines Not supported for write-only file.
Method seek Seek to position in file.
Method seekable Check if file is seekable.
Method tell Return current file position.
Method truncate Not supported for write-only file.
Method writable Check if file is writable.
Method write Write data and update hash.
Method write_hash Write the hash digest to the file.
Method writelines Write multiple lines to the file.
Instance Variable digest Undocumented
Instance Variable f Undocumented
Instance Variable hash_obj Undocumented
Instance Variable length Undocumented
def __enter__(self) -> HashWriter:

Enter context manager.

def __exit__(self, type: type | None, value: BaseException | None, traceback: TracebackType | None):

Exit context manager and close file.

def __init__(self, f: BinaryIO | IO[bytes], hash_func: Callable[[], HashObject]):

Initialize HashWriter.

Parameters
f:BinaryIO | IO[bytes]File-like object to wrap
hash_func:Callable[[], HashObject]Hash function (e.g., sha1, sha256)
def __iter__(self) -> HashWriter:

Return iterator.

def __next__(self) -> bytes:

Not supported for write-only file.

Raises
UnsupportedOperationAlways raised
def close(self):

Close the pack file and finalize the hash.

def fileno(self) -> int:

Return file descriptor number.

def flush(self):

Flush the file buffer.

def isatty(self) -> bool:

Check if file is a terminal.

def offset(self) -> int:

Get the total number of bytes written.

Returns
intTotal bytes written
def read(self, size: int = -1) -> bytes:

Not supported for write-only file.

Raises
UnsupportedOperationAlways raised
def readable(self) -> bool:

Check if file is readable.

def readline(self, size: int = -1) -> bytes:

Not supported for write-only file.

Raises
UnsupportedOperationAlways raised
def readlines(self, hint: int = -1) -> list[bytes]:

Not supported for write-only file.

Raises
UnsupportedOperationAlways raised
def seek(self, offset: int, whence: int = 0) -> int:

Seek to position in file.

Parameters
offset:intPosition offset
whence:intReference point (0=start, 1=current, 2=end)
Returns
intNew file position
def seekable(self) -> bool:

Check if file is seekable.

def tell(self) -> int:

Return current file position.

def truncate(self, size: int | None = None) -> int:

Not supported for write-only file.

Raises
UnsupportedOperationAlways raised
def writable(self) -> bool:

Check if file is writable.

def write(self, data: bytes | bytearray | memoryview, /) -> int:

Write data and update hash.

Parameters
data:bytes | bytearray | memoryviewData to write
Returns
intNumber of bytes written
def write_hash(self) -> bytes:

Write the hash digest to the file.

Returns
bytesThe hash digest bytes
def writelines(self, lines: Iterable[bytes], /):

Write multiple lines to the file.

Parameters
lines:Iterable[bytes]Iterable of lines to write
digest: bytes | None =

Undocumented

f =

Undocumented

hash_obj =

Undocumented

length: int =

Undocumented