@@ -39,16 +39,16 @@ Directory and files operations
39
39
40
40
.. function :: copyfileobj(fsrc, fdst[, length])
41
41
42
- Copy the contents of the file-like object *fsrc * to the file-like object *fdst *.
43
- The integer *length *, if given, is the buffer size. In particular, a negative
44
- *length * value means to copy the data without looping over the source data in
45
- chunks; by default the data is read in chunks to avoid uncontrolled memory
46
- consumption. Note that if the current file position of the *fsrc * object is not
47
- 0, only the contents from the current file position to the end of the file will
48
- be copied.
42
+ Copy the contents of the file-like object *fsrc * to the file-like object
43
+ *fdst *. Only the contents from the current file position to the end of
44
+ the file will be copied.
49
45
46
+ The integer *length *, if given, is the buffer size; the default value
47
+ in bytes is 16 KiB. A negative *length * value means to copy the data without
48
+ looping over the source data in chunks; by default the data is read in
49
+ chunks to avoid uncontrolled memory consumption.
50
50
51
- .. function :: copyfile(src, dst, *, follow_symlinks=True)
51
+ .. function :: copyfile(src, dst, *, follow_symlinks=True, length=None )
52
52
53
53
Copy the contents (no metadata) of the file named *src * to a file named
54
54
*dst * and return *dst *. *src * and *dst * are path names given as strings.
@@ -65,6 +65,9 @@ Directory and files operations
65
65
a new symbolic link will be created instead of copying the
66
66
file *src * points to.
67
67
68
+ The integer *length *, if given, is the in-memory buffer size; the default
69
+ value in bytes is 16 KiB (see :func: `shutil.copyfileobj `).
70
+
68
71
.. versionchanged :: 3.3
69
72
:exc: `IOError ` used to be raised instead of :exc: `OSError `.
70
73
Added *follow_symlinks * argument.
@@ -74,6 +77,9 @@ Directory and files operations
74
77
Raise :exc: `SameFileError ` instead of :exc: `Error `. Since the former is
75
78
a subclass of the latter, this change is backward compatible.
76
79
80
+ .. versionchanged :: 3.7
81
+ Added *length * parameter.
82
+
77
83
78
84
.. exception :: SameFileError
79
85
@@ -141,7 +147,7 @@ Directory and files operations
141
147
.. versionchanged :: 3.3
142
148
Added *follow_symlinks * argument and support for Linux extended attributes.
143
149
144
- .. function :: copy(src, dst, *, follow_symlinks=True)
150
+ .. function :: copy(src, dst, *, follow_symlinks=True, length=None )
145
151
146
152
Copies the file *src * to the file or directory *dst *. *src * and *dst *
147
153
should be strings. If *dst * specifies a directory, the file will be
@@ -153,6 +159,9 @@ Directory and files operations
153
159
is true and *src * is a symbolic link, *dst * will be a copy of
154
160
the file *src * refers to.
155
161
162
+ The integer *length *, if given, is the in-memory buffer size; the default
163
+ value in bytes is 16 KiB (see :func: `shutil.copyfileobj `).
164
+
156
165
:func: `~shutil.copy ` copies the file data and the file's permission
157
166
mode (see :func: `os.chmod `). Other metadata, like the
158
167
file's creation and modification times, is not preserved.
@@ -163,7 +172,11 @@ Directory and files operations
163
172
Added *follow_symlinks * argument.
164
173
Now returns path to the newly created file.
165
174
166
- .. function :: copy2(src, dst, *, follow_symlinks=True)
175
+ .. versionchanged :: 3.7
176
+ Added `length ` parameter
177
+
178
+
179
+ .. function :: copy2(src, dst, *, follow_symlinks=True, length=None)
167
180
168
181
Identical to :func: `~shutil.copy ` except that :func: `copy2 `
169
182
also attempts to preserve all file metadata.
@@ -176,6 +189,9 @@ Directory and files operations
176
189
unavailable, :func: `copy2 ` will preserve all the metadata
177
190
it can; :func: `copy2 ` never returns failure.
178
191
192
+ The integer *length *, if given, is the in-memory buffer size; the default
193
+ value in bytes is 16 KiB (see :func: `shutil.copyfileobj `).
194
+
179
195
:func: `copy2 ` uses :func: `copystat ` to copy the file metadata.
180
196
Please see :func: `copystat ` for more information
181
197
about platform support for modifying symbolic link metadata.
@@ -185,6 +201,10 @@ Directory and files operations
185
201
file system attributes too (currently Linux only).
186
202
Now returns path to the newly created file.
187
203
204
+ .. versionchanged :: 3.7
205
+ Added `length ` parameter
206
+
207
+
188
208
.. function :: ignore_patterns(\*patterns)
189
209
190
210
This factory function creates a function that can be used as a callable for
0 commit comments