o
    *ήc)                     @   s@   zd dl Z W n	 ey   Y nw dZdd Zdd Zdd ZdS )	    Ni    c                 C   s<   t | d}t|tW  d   S 1 sw   Y  dS )z
    Reads file from disk and returns the first 8192 bytes
    of data representing the magic number header signature.

    Args:
        path: path string to file.

    Returns:
        First 8192 bytes of the file content as bytearray type.
    rbN)open	bytearrayread_NUM_SIGNATURE_BYTES)pathfp r	   5/tmp/pip-target-vg8gfxp4/lib/python/filetype/utils.pyget_signature_bytes   s   $r   c                 C   s$   t | }|tkr
tn|}| d| S )z
    Returns the first 8192 bytes of the given bytearray
    as part of the file header signature.

    Args:
        array: bytearray to extract the header signature.

    Returns:
        First 8192 bytes of the file content as bytearray type.
    N)lenr   )arraylengthindexr	   r	   r
   	signature   s   r   c                 C   s   t | tr	t| S t | trt| S t | trt| S t | tr(tt|  S t | tj	r2t| S t
| dr_t
| drXt
| drX|  }| d | t}| | t|S t| tS tdt|  )af  
    Infers the input type and reads the first 8192 bytes,
    returning a sliced bytearray.

    Args:
        obj: path to readable, file-like object(with read() method), bytes,
        bytearray or memoryview

    Returns:
        First 8192 bytes of the file content as bytearray type.

    Raises:
        TypeError: if obj is not a supported type.
    r   tellseekr   z"Unsupported type as file input: %s)
isinstancer   r   strr   bytes
memoryviewtolistpathlibPurePathhasattrr   r   r   r   	get_bytes	TypeErrortype)obj	start_posmagic_bytesr	   r	   r
   r   -   s&   







r   )r   ImportErrorr   r   r   r   r	   r	   r	   r
   <module>   s   