Skip to content

Commit

Permalink
addressed PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
amystamile-usgs committed May 30, 2024
1 parent 33d5d77 commit ac5d28f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
36 changes: 18 additions & 18 deletions ale/isd_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,56 +208,56 @@ def write_json_file(isd_string, json_file):
with open(json_file, 'w') as fp:
json.dump(isd_string, fp, cls = AleJsonEncoder)

def compress_isd(uncompressed_isd_file):
def compress_json(uncompressed_json_file):
"""
Compresses inputted isd .json file.
Compresses inputted .json file.
Parameters
----------
uncompressed_isd_file : str
uncompressed_json_file : str
.json file path
Returns
-------
str
Compressed .br file path
"""
if not uncompressed_isd_file.split(".")[1] == 'json':
raise ValueError("Inputted file {} is not a valid .json file extension".format(uncompressed_isd_file.split(".")[1]))
with open(uncompressed_isd_file, 'rb') as f:
if not os.path.splitext(uncompressed_json_file)[1] == '.json':
raise ValueError("Inputted file {} is not a valid .json file extension".format(uncompressed_json_file.split(".")[1]))
with open(uncompressed_json_file, 'rb') as f:
data = f.read()
with open(uncompressed_isd_file, 'wb') as f:
with open(uncompressed_json_file, 'wb') as f:
f.write(brotli.compress(data))

os.rename(uncompressed_isd_file, os.path.splitext(uncompressed_isd_file)[0] + '.br')
os.rename(uncompressed_json_file, os.path.splitext(uncompressed_json_file)[0] + '.br')

return os.path.splitext(uncompressed_isd_file)[0] + '.br'
return os.path.splitext(uncompressed_json_file)[0] + '.br'


def decompress_isd(compressed_isd_file):
def decompress_json(compressed_json_file):
"""
Decompresses inputted isd .br file.
Decompresses inputted .br file.
Parameters
----------
compressed_isd_file : str
compressed_json_file : str
.br file path
Returns
-------
str
Decompressed .json file path
"""
if not compressed_isd_file.split(".")[1] == 'br':
raise ValueError("Inputted file {} is not a valid .br file extension".format(compressed_isd_file))
with open(compressed_isd_file, 'rb') as f:
if not os.path.splitext(compressed_json_file)[1] == '.br':
raise ValueError("Inputted file {} is not a valid .br file extension".format(compressed_json_file))
with open(compressed_json_file, 'rb') as f:
data = f.read()
with open(compressed_isd_file, 'wb') as f:
with open(compressed_json_file, 'wb') as f:
f.write(brotli.decompress(data))

os.rename(compressed_isd_file, os.path.splitext(compressed_isd_file)[0] + '.json')
os.rename(compressed_json_file, os.path.splitext(compressed_json_file)[0] + '.json')

return os.path.splitext(compressed_isd_file)[0] + '.json'
return os.path.splitext(compressed_json_file)[0] + '.json'

if __name__ == "__main__":
try:
Expand Down
4 changes: 2 additions & 2 deletions tests/pytests/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def test_compress_decompress():

isdg.write_json_file(isd_str, json_file)

compressed_file = isdg.compress_isd(json_file)
compressed_file = isdg.compress_json(json_file)

decompressed_file = isdg.decompress_isd(compressed_file)
decompressed_file = isdg.decompress_json(compressed_file)

with open(decompressed_file, 'r') as fp:
isis_dict = json.load(fp)
Expand Down

0 comments on commit ac5d28f

Please sign in to comment.