(target_dir, source)
return
Deposit file stream into a target directory.
Deposit file stream into a target directory.
Deposit file stream into a target directory .
def add_file(target_dir, source):
    """
    Deposit file stream into a target directory.
    """

    # Link an existing file
    if isinstance(source, str) and os.path.exists(source):
        return link_file(source=source, target_dir=target_dir)

    # Write a stream to a new file
    if hasattr(source, 'read'):
        # Get the absolute path
        dest = os.path.abspath(target_dir)

        # Create the directory
        os.makedirs(dest, exist_ok=True)

        # Get the name
        fname = source.name

        path = os.path.abspath(os.path.join(dest, fname))
        # Write the stream into file.
        util.write_stream(stream=source, dest=path)

        return path

    return
def add_file ( target_dir , source ) : # Link an existing file if isinstance ( source , str ) and os . path . exists ( source ) : return link_file ( source = source , target_dir = target_dir ) # Write a stream to a new file if hasattr ( source , 'read' ) : # Get the absolute path dest = os . path . abspath ( target_dir ) # Create the directory os . makedirs ( dest , exist_ok = True ) # Get the name fname = source . name path = os . path . abspath ( os . path . join ( dest , fname ) ) # Write the stream into file. util . write_stream ( stream = source , dest = path ) return path return