o
    QDi                     @  s|   d dl mZ d dlmZmZmZmZ ddlmZ ddl	m
Z
 ddlmZ G dd deZG d	d
 d
eZG dd deZdS )    )annotations)AnyOptionalUnioncast   )helpers)FrictionlessException)Resourcec                   @  s2   e Zd ZdZdZddddd	Z	ddddZdS )FileResourcefileN)sizer   Optional[int]returnbytesc                C  s   | j rt| jtr| jS t| , |s0d}	 tt| j }||7 }|s&nq|W  d   S | j|W  d   S 1 s@w   Y  dS )zURead bytes into memory

        Returns:
            any[][]: resource bytes
            TN)	memory
isinstancedatar   r   ensure_openr   byte_streamread1)selfr   bufferchunk r   T/var/www/Datamplify/venv/lib/python3.10/site-packages/frictionless/resources/file.py	read_file   s    
$zFileResource.read_filetarget"Optional[Union[FileResource, str]]optionsr   c                 K  sV   |}t |tstdi |}t |tstd|  }|js J tj|j|dd |S )zWrite bytes to the targetztarget must be a text resourcewb)modeNr   )r   r
   r   r	   r   normpathr   
write_file)r   r   r    resourcer   r   r   r   r$   +   s   


zFileResource.write_file)r   r   r   r   )N)r   r   r    r   )__name__
__module____qualname__typedatatyper   r$   r   r   r   r   r   
   s    r   c                   @     e Zd ZdZdS )ImageResourceimageNr&   r'   r(   r*   r   r   r   r   r,   :       r,   c                   @  r+   )DocumentResourcedocumentNr.   r   r   r   r   r0   >   r/   r0   N)
__future__r   typingr   r   r   r    r   	exceptionr	   r%   r
   r   r,   r0   r   r   r   r   <module>   s    0