MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / _load_sb3_file

Function _load_sb3_file

scratchattach/other/project_json_capabilities.py:440–452  ·  view source on GitHub ↗
(path_to_file)

Source from the content-addressed store, hash-verified

438 pb.from_json(project_json)
439 return pb
440def _load_sb3_file(path_to_file):
441 try:
442 with open(path_to_file, "r") as r:
443 return json.loads(r.read())
444 except Exception as e:
445 with zipfile.ZipFile(path_to_file, 'r') as zip_ref:
446 # Check if the file exists in the zip
447 if "project.json" in zip_ref.namelist():
448 # Read the file as bytes
449 with zip_ref.open("project.json") as file:
450 return json.loads(file.read())
451 else:
452 raise ValueError("specified sb3 archive doesn't contain project.json")
453def read_sb3_file(path_to_file):
454 pb = ProjectBody()
455 pb.from_json(_load_sb3_file(path_to_file))

Callers 1

read_sb3_fileFunction · 0.85

Calls 1

readMethod · 0.45

Tested by

no test coverage detected