Add the TarInfo object `tarinfo' to the archive. If `fileobj' is given, it should be a binary file, and tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects directly, or by using gettarinfo().
(self, tarinfo, fileobj=None)
| 2191 | self.addfile(tarinfo) |
| 2192 | |
| 2193 | def addfile(self, tarinfo, fileobj=None): |
| 2194 | """Add the TarInfo object `tarinfo' to the archive. If `fileobj' is |
| 2195 | given, it should be a binary file, and tarinfo.size bytes are read |
| 2196 | from it and added to the archive. You can create TarInfo objects |
| 2197 | directly, or by using gettarinfo(). |
| 2198 | """ |
| 2199 | self._check("awx") |
| 2200 | |
| 2201 | tarinfo = copy.copy(tarinfo) |
| 2202 | |
| 2203 | buf = tarinfo.tobuf(self.format, self.encoding, self.errors) |
| 2204 | self.fileobj.write(buf) |
| 2205 | self.offset += len(buf) |
| 2206 | bufsize=self.copybufsize |
| 2207 | # If there's data to follow, append it. |
| 2208 | if fileobj is not None: |
| 2209 | copyfileobj(fileobj, self.fileobj, tarinfo.size, bufsize=bufsize) |
| 2210 | blocks, remainder = divmod(tarinfo.size, BLOCKSIZE) |
| 2211 | if remainder > 0: |
| 2212 | self.fileobj.write(NUL * (BLOCKSIZE - remainder)) |
| 2213 | blocks += 1 |
| 2214 | self.offset += blocks * BLOCKSIZE |
| 2215 | |
| 2216 | self.members.append(tarinfo) |
| 2217 | |
| 2218 | def _get_filter_function(self, filter): |
| 2219 | if filter is None: |