import hashlib


def calc_hash(s3_object, chunk_size=1024 * 1024):
    """Calculate md5 and sha256 hash for an object chunk by chunk."""
    md5_hash = hashlib.md5()
    sha_hash = hashlib.sha256()
    chunk = s3_object.read(chunk_size)
    while chunk:
        md5_hash.update(chunk)
        sha_hash.update(chunk)
        chunk = s3_object.read(chunk_size)

    return {
        'md5': md5_hash.hexdigest(),
        'sha256': sha_hash.hexdigest(),
    }