MCPcopy Index your code
hub / github.com/algorithmiaio/algorithmia-python / getAsZip

Method getAsZip

Algorithmia/datafile.py:54–69  ·  view source on GitHub ↗

Download/decompress file/directory and return path to file/directory. Expects the `DataFile` object to contain a data API path pointing to a file/directory compressed with a zip-based compression algorithm. Either returns the directory or a path to the file, depending on whe

(self)

Source from the content-addressed store, hash-verified

52 return open(f.name)
53
54 def getAsZip(self):
55 """Download/decompress file/directory and return path to file/directory.
56
57 Expects the `DataFile` object to contain a data API path pointing to a file/directory compressed with a zip-based compression algorithm.
58 Either returns the directory or a path to the file, depending on whether a directory or file was zipped.
59 """
60 local_file_path = self.getFile(as_path=True)
61 directory_path = tempfile.mkdtemp()
62 with zipfile.ZipFile(local_file_path, 'r') as ziph:
63 ziph.extractall(directory_path)
64 if len(ziph.namelist()) > 1:
65 output_path = directory_path
66 else:
67 filename = ziph.namelist()[0]
68 output_path = os.path.join(directory_path, filename)
69 return output_path
70
71 def getName(self):
72 _, name = getParentAndBase(self.path)

Callers 1

Calls 1

getFileMethod · 0.95

Tested by 1