Calculate the checksum for a member's header by summing up all characters except for the chksum field which is treated as if it was filled with spaces. According to the GNU tar sources, some tars (Sun and NeXT) calculate chksum with signed char, which will be different if
(buf)
| 219 | return s |
| 220 | |
| 221 | def calc_chksums(buf): |
| 222 | """Calculate the checksum for a member's header by summing up all |
| 223 | characters except for the chksum field which is treated as if |
| 224 | it was filled with spaces. According to the GNU tar sources, |
| 225 | some tars (Sun and NeXT) calculate chksum with signed char, |
| 226 | which will be different if there are chars in the buffer with |
| 227 | the high bit set. So we calculate two checksums, unsigned and |
| 228 | signed. |
| 229 | """ |
| 230 | unsigned_chksum = 256 + sum(struct.unpack_from("148B8x356B", buf)) |
| 231 | signed_chksum = 256 + sum(struct.unpack_from("148b8x356b", buf)) |
| 232 | return unsigned_chksum, signed_chksum |
| 233 | |
| 234 | def copyfileobj(src, dst, length=None, exception=OSError, bufsize=None): |
| 235 | """Copy length bytes from fileobj src to fileobj dst. |
no outgoing calls
no test coverage detected
searching dependent graphs…