• Home
  • Raw
  • Download

Lines Matching +full:tar +full:- +full:stream

1 # -*- coding: iso-8859-1 -*-
2 #-------------------------------------------------------------------
4 #-------------------------------------------------------------------
29 """Read from and write to tar format archives.
41 #---------
43 #---------
64 #---------------------------------------------------------
65 # tar constants
66 #---------------------------------------------------------
70 GNU_MAGIC = "ustar \0" # magic gnu tar string
71 POSIX_MAGIC = "ustar\x0000" # magic posix tar string
87 GNUTYPE_LONGNAME = "L" # GNU tar longname
88 GNUTYPE_LONGLINK = "K" # GNU tar longlink
89 GNUTYPE_SPARSE = "S" # GNU tar sparse file
91 XHDTYPE = "x" # POSIX.1-2001 extended header
92 XGLTYPE = "g" # POSIX.1-2001 global header
95 USTAR_FORMAT = 0 # POSIX.1-1988 (ustar) format
96 GNU_FORMAT = 1 # GNU tar format
97 PAX_FORMAT = 2 # POSIX.1-2001 (pax) format
100 #---------------------------------------------------------
102 #---------------------------------------------------------
114 # File types that are part of the GNU tar format.
133 #---------------------------------------------------------
135 #---------------------------------------------------------
157 #---------------------------------------------------------
159 #---------------------------------------------------------
164 #---------------------------------------------------------
166 #---------------------------------------------------------
169 """Convert a python string to a null-terminated string buffer.
171 return s[:length] + (length - len(s)) * NUL
174 """Convert a null-terminated string field to a python string.
178 if p == -1:
194 for i in xrange(len(s) - 1):
202 # POSIX 1003.1-1988 requires numbers to be encoded as a string of
203 # octal digits followed by a null-byte, this allows values up to
204 # (8**(digits-1))-1. GNU tar allows storing numbers greater than
206 # encoding, the following digits-1 bytes are a big-endian
207 # representation. This allows values up to (256**(digits-1))-1.
208 if 0 <= n < 8 ** (digits - 1):
209 s = "%0*o" % (digits - 1, n) + NUL
211 if format != GNU_FORMAT or n >= 256 ** (digits - 1):
215 # XXX We mimic GNU tar's behaviour with negative numbers,
220 for i in xrange(digits - 1):
229 if errors == "utf-8":
230 # An extra error handler similar to the -o invalid=UTF-8 option
231 # in POSIX.1-2001. Replace untranslatable characters with their
232 # UTF-8 representation.
249 it was filled with spaces. According to the GNU tar sources,
286 (S_IFREG, "-"),
313 -rwxrwxrwx.
323 perm.append("-")
333 """Exception for unreadable tar archives."""
339 """Exception for unsupported operations on stream-like TarFiles."""
360 #---------------------------
361 # internal stream interface
362 #---------------------------
364 """Low-level file object. Supports reading and writing.
389 a stream-like object. The stream-like object only
392 A stream-like object could be for example: sys.stdin,
408 # stream interface
458 -self.zlib.MAX_WBITS,
464 self.name = self.name.encode("iso-8859-1", "replace")
466 self.name = self.name[:-3]
470 """Write string s to the stream.
475 if self.comptype != "tar":
480 """Write string s to the stream if a whole new block
497 if self.mode == "w" and self.comptype != "tar":
504 # The native zlib crc is an unsigned 32-bit integer, but
506 # long. So, on a 32-bit box self.crc may "look negative",
507 # while the same crc on a 64-bit box may "look positive".
519 self.cmp = self.zlib.decompressobj(-self.zlib.MAX_WBITS)
548 """Return the stream's file pointer position.
553 """Set the stream's file pointer to pos. Negative seeking
556 if pos - self.pos >= 0:
557 blocks, remainder = divmod(pos - self.pos, self.bufsize)
566 """Return the next size number of bytes from the stream.
567 If size is not defined, return all bytes of the stream
584 """Return size bytes from the stream.
586 if self.comptype == "tar":
606 """Return size bytes from stream. If internal buffer is empty,
607 read another block from the stream.
624 detection for the Stream interface (mode 'r|*').
640 return "tar"
692 self.read(pos - self.pos)
708 #------------------------
710 #------------------------
738 size = self.size - self.position
740 size = min(size, self.size - self.position)
768 size -= len(buf)
780 size = min(size, section.offset + section.size - self.position)
783 realpos = section.realpos + self.position - section.offset
794 """File-like object for reading an archive member.
831 buf += self.fileobj.read(size - len(buf))
836 def readline(self, size=-1):
838 and non-negative, return a string with at most that
859 if size != -1:
921 #------------------
923 #------------------
926 archive member given by a tar header block.
950 self.offset = 0 # the tar header starts here
1001 """Return a tar header as a string of 512 byte blocks.
1080 if not 0 <= val < 8 ** (digits - 1) or isinstance(val, float):
1103 while prefix and prefix[-1] != "/":
1104 prefix = prefix[:-1]
1107 prefix = prefix[:-1]
1137 chksum = calc_chksums(buf[-BLOCKSIZE:])[0]
1138 buf = buf[:-364] + "%06o\0" % chksum + buf[-357:]
1148 payload += (BLOCKSIZE - remainder) * NUL
1170 """Return a POSIX.1-2001 extended or global header sequence
1232 # Old V7 tar format represents a directory as a regular
1253 obj.offset = tarfile.fileobj.tell() - BLOCKSIZE
1256 #--------------------------------------------------------------------------
1336 sp.append(_hole(lastpos, offset - lastpos))
1357 sp.append(_hole(lastpos, offset - lastpos))
1365 sp.append(_hole(lastpos, origsize - lastpos))
1377 POSIX.1-2001.
1393 # the newline. keyword and value are both UTF-8 encoded strings.
1403 value = buf[match.end(2) + 1:match.start(1) + length - 1]
1488 """The TarFile Class provides an interface to tar archives.
1494 # tar file, else the link.
1505 encoding = ENCODING # Encoding for 8-bit character strings.
1516 """Open an (uncompressed) tar archive `name'. `mode' is either 'r' to
1561 self.errors = "utf-8"
1628 #--------------------------------------------------------------------------
1631 # public use; it is the "super"-constructor and is able to select an
1632 # adequate "sub"-constructor for a particular compression using the mapping
1636 # the super-constructor. A sub-constructor is registered and made available
1641 """Open a tar archive for reading, writing or appending. Return
1654 'r|*' open a stream of tar blocks with transparent compression
1655 'r|' open an uncompressed stream of tar blocks for reading
1656 'r|gz' open a gzip compressed stream of tar blocks
1657 'r|bz2' open a bzip2 compressed stream of tar blocks
1658 'w|' open an uncompressed stream for writing
1659 'w|gz' open a gzip compressed stream for writing
1660 'w|bz2' open a bzip2 compressed stream for writing
1685 comptype = comptype or "tar"
1698 comptype = comptype or "tar"
1703 stream = _Stream(name, filemode, comptype, fileobj, bufsize)
1705 t = cls(name, filemode, stream, **kwargs)
1707 stream.close()
1719 """Open uncompressed tar archive name for reading or writing.
1727 """Open gzip compressed tar archive name for reading or writing.
1761 """Open bzip2 compressed tar archive name for reading or writing.
1792 "tar": "taropen", # uncompressed tar
1793 "gz": "gzopen", # gzip compressed tar
1794 "bz2": "bz2open" # bzip2 compressed tar
1797 #--------------------------------------------------------------------------
1801 """Close the TarFile. In write-mode, two finishing zero blocks are
1812 # fill up the end with zero-blocks
1813 # (like option -b20 for tar does)
1816 self.fileobj.write(NUL * (RECORDSIZE - remainder))
1825 most up-to-date version.
1949 the names of the members are printed. If it is True, an `ls -l'-like
1964 print "%d-%02d-%02d %02d:%02d:%02d" \
1971 print "->", tarinfo.linkname,
2022 # Append the tar header and data to the archive.
2057 self.fileobj.write(NUL * (BLOCKSIZE - remainder))
2136 file-like object is returned. If `member' is a link, a file-like
2139 The file-like object is read-only and provides the following
2160 # to extract a (sym)link as a file-object from a non-seekable
2161 # stream of tar blocks.
2189 self._dbg(1, "%s -> %s" % (tarinfo.name, tarinfo.linkname))
2213 #--------------------------------------------------------------------------
2336 #--------------------------------------------------------------------------
2350 self.fileobj.seek(self.offset - 1)
2388 #--------------------------------------------------------------------------
2475 # it would try to write end-of-archive blocks and padding.
2562 #---------------------------------------------
2564 #---------------------------------------------
2616 #--------------------
2618 #--------------------
2620 """Return True if name points to a tar archive that we