MCPcopy Create free account
hub / github.com/alibaba/GraphScope / InMemoryZip

Class InMemoryZip

python/graphscope/analytical/udf/utils.py:255–293  ·  view source on GitHub ↗

InMemoryZip is used to generate a gar file during runtime, without touching the disk.

Source from the content-addressed store, hash-verified

253
254
255class InMemoryZip(object):
256 """InMemoryZip is used to generate a gar file during runtime, without touching the disk."""
257
258 def __init__(self):
259 self.in_memory_buffer = BytesIO()
260 self.zip_file = zipfile.ZipFile(
261 self.in_memory_buffer, "a", zipfile.ZIP_DEFLATED, False
262 )
263
264 def append(self, filepath, content):
265 """Append a file to the zip file.
266
267 Parameters
268 ----------
269 filepath: str
270 The path to write the file in the zip file.
271 content: str or bytes
272 The content that will be written into the zip file.
273
274 See Also
275 --------
276 ZipFile.writestr: write file to zip files.
277 """
278 self.zip_file.writestr(zipfile.ZipInfo(filepath), content)
279
280 def read_bytes(self, raw=False):
281 """Read bytes value of the zip file.
282
283 Parameters
284 ----------
285 raw: bool
286 If True, return the raw bytes. Otherwise return the BytesIO object.
287 """
288 # close the file first before reading bytes, close repeatedly is OK.
289 self.zip_file.close()
290 if raw:
291 return self.in_memory_buffer.getvalue()
292 else:
293 return self.in_memory_buffer

Callers 3

add_libMethod · 0.90
wrap_initFunction · 0.90
_pack_jarMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected