Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/segmentation_skeleton_metrics/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,21 @@ def list_paths(directory, extension=None):


# --- IO Utils ---
def read_zip(zip_file, path):
def read_json(path):
"""
Reads a txt file contained in the given ZIP archive.
Reads JSON file located at the given path.

Parameters
----------
zip_file : ZipFile
ZIP archive containing TXT file.
path : str
Path to JSON file to be read.

Returns
-------
str
Contents of a TXT file.
dict
Contents of JSON file.
"""
with zip_file.open(path) as f:
return f.read().decode("utf-8")
return pd.read_json(path, storage_options={"anon": True}, typ="series")


def read_txt(path):
Expand All @@ -174,6 +173,24 @@ def read_txt(path):
return f.read().splitlines()


def read_zip(zip_file, path):
"""
Reads txt file contained in the given ZIP archive.

Parameters
----------
zip_file : ZipFile
ZIP archive containing TXT file.

Returns
-------
str
Contents of a TXT file.
"""
with zip_file.open(path) as f:
return f.read().decode("utf-8")


def update_txt(path, text, verbose=True):
"""
Appends the given text to a specified text file and prints the text.
Expand Down
Loading