Datasets:

Languages:
English
ArXiv:
License:
File size: 1,243 Bytes
b51f134
 
62cd5a4
dd3a1b3
 
62cd5a4
 
 
 
 
 
 
 
 
 
 
 
 
dd3a1b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Utility functions for the objaverse_xl package."""

import uuid
import os
import hashlib


def get_uid_from_str(string: str) -> str:
    """Generates a UUID from a string.

    Args:
        string (str): String to generate a UUID from.

    Returns:
        str: UUID generated from the string.
    """
    namespace = uuid.NAMESPACE_DNS
    return str(uuid.uuid5(namespace, string))


def get_file_hash(file_path: str) -> str:
    """Get the sha256 hash of a file.

    Args:
        file_path (str): Path to the file.

    Returns:
        str: sha256 hash of the file.
    """
    # Check if the path is a symbolic link
    if os.path.islink(file_path):
        # Resolve the symbolic link
        resolved_path = os.readlink(file_path)
        # Check if the resolved path exists
        if not os.path.exists(resolved_path):
            raise FileNotFoundError(
                f"The symbolic link points to a file that doesn't exist: {resolved_path}"
            )
    sha256 = hashlib.sha256()
    # Read the file from the path
    with open(file_path, "rb") as f:
        # Loop till the end of the file
        for byte_block in iter(lambda: f.read(4096), b""):
            sha256.update(byte_block)
    return sha256.hexdigest()