nvflare.fuel.utils.zip_utils module

get_all_file_paths(directory)[source]

Gets all file paths in the directory.

Parameters:

directory – directory to get all paths for

Returns:

A list of paths of all the files in the provided directory

ls_zip_from_bytes(zip_data: bytes)[source]

Returns info of a zip.

Parameters:

zip_data – the input zip data

normpath_for_zip(path)[source]

Normalizes the path for zip file.

Parameters:

path (str) – the path to be normalized

remove_leading_dotdot(path: str) str[source]
split_path(path: str) -> (<class 'str'>, <class 'str'>)[source]

Splits a path into a pair of head and tail.

It removes trailing os.path.sep and call os.path.split

Parameters:

path – Path to split

Returns:

A tuple of (head, tail)

unzip_all_from_bytes(zip_data: bytes, output_dir_name: str)[source]

Decompresses a zip and extracts all files to the specified output directory.

Parameters:
  • zip_data – the input zip data

  • output_dir_name – the output directory for extracted content

unzip_all_from_file(zip_file_path: str, output_dir_name: str)[source]
unzip_single_file_from_bytes(zip_data: bytes, output_dir_name: str, file_path: str)[source]

Decompresses a zip and extracts single specified file to the specified output directory.

Parameters:
  • zip_data – the input zip data

  • output_dir_name – the output directory for extracted content

  • file_path – file path to file to unzip

zip_directory_to_bytes(root_dir: str, folder_name: str) bytes[source]

Compresses a directory and return the bytes value of it.

Parameters:
  • root_dir – root path that contains the folder to be zipped

  • folder_name – path to the folder to be zipped, relative to root_dir

zip_directory_to_file(root_dir: str, folder_name: str, output_file)[source]

Compresses a directory and return the bytes value of it.

Parameters:
  • root_dir – root path that contains the folder to be zipped

  • folder_name – path to the folder to be zipped, relative to root_dir

  • output_file – path of the output file