MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / save

Method save

21-async/mojifinder/bottle.py:2397–2414  ·  view source on GitHub ↗

Save file to disk or copy its content to an open file(-like) object. If *destination* is a directory, :attr:`filename` is added to the path. Existing files are not overwritten by default (IOError). :param destination: File path, directory or file(-like) object.

(self, destination, overwrite=False, chunk_size=2**16)

Source from the content-addressed store, hash-verified

2395 self.file.seek(offset)
2396
2397 def save(self, destination, overwrite=False, chunk_size=2**16):
2398 ''' Save file to disk or copy its content to an open file(-like) object.
2399 If *destination* is a directory, :attr:`filename` is added to the
2400 path. Existing files are not overwritten by default (IOError).
2401
2402 :param destination: File path, directory or file(-like) object.
2403 :param overwrite: If True, replace existing files. (default: False)
2404 :param chunk_size: Bytes to read at a time. (default: 64kb)
2405 '''
2406 if isinstance(destination, basestring): # Except file-likes here
2407 if os.path.isdir(destination):
2408 destination = os.path.join(destination, self.filename)
2409 if not overwrite and os.path.exists(destination):
2410 raise IOError('File exists.')
2411 with open(destination, 'wb') as fp:
2412 self._copy_file(fp, chunk_size)
2413 else:
2414 self._copy_file(destination, chunk_size)
2415
2416
2417

Callers

nothing calls this directly

Calls 1

_copy_fileMethod · 0.95

Tested by

no test coverage detected