當前位置: 首頁>>代碼示例>>Python>>正文


Python tarfile.BLOCKSIZE屬性代碼示例

本文整理匯總了Python中tarfile.BLOCKSIZE屬性的典型用法代碼示例。如果您正苦於以下問題:Python tarfile.BLOCKSIZE屬性的具體用法?Python tarfile.BLOCKSIZE怎麽用?Python tarfile.BLOCKSIZE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在tarfile的用法示例。


在下文中一共展示了tarfile.BLOCKSIZE屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: format_sparse_map

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import BLOCKSIZE [as 別名]
def format_sparse_map(self):
        sparsemap_txt = (str(len(self.sparsemap)) + '\n' +
            ''.join('{}\n{}\n'.format(*entry) for entry in self.sparsemap))
        sparsemap_txt_len = len(sparsemap_txt)
        if sparsemap_txt_len % tarfile.BLOCKSIZE:
            padding = '\0' * (tarfile.BLOCKSIZE -
                              sparsemap_txt_len % tarfile.BLOCKSIZE)
        else:
            padding = ''
        return (sparsemap_txt + padding).encode() 
開發者ID:QubesOS,項目名稱:qubes-core-admin,代碼行數:12,代碼來源:tarwriter.py

示例2: get_sparse_map

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import BLOCKSIZE [as 別名]
def get_sparse_map(input_file):
    '''
    Return map of the file where actual data is present, ignoring zero-ed
    blocks. Last entry of the map spans to the end of file, even if that part is
    zero-size (when file ends with zeros).

    This function is performance critical.

    :param input_file: io.File object
    :return: iterable of (offset, size)
    '''
    zero_block = bytearray(tarfile.BLOCKSIZE)
    buf = bytearray(BUF_SIZE)
    in_data_block = False
    data_block_start = 0
    buf_start_offset = 0
    while True:
        buf_len = input_file.readinto(buf)
        if not buf_len:
            break
        for offset in range(0, buf_len, tarfile.BLOCKSIZE):
            if buf[offset:offset+tarfile.BLOCKSIZE] == zero_block:
                if in_data_block:
                    in_data_block = False
                    yield (data_block_start,
                        buf_start_offset+offset-data_block_start)
            else:
                if not in_data_block:
                    in_data_block = True
                    data_block_start = buf_start_offset+offset
        buf_start_offset += buf_len
    if in_data_block:
        yield (data_block_start, buf_start_offset-data_block_start)
    else:
        # always emit last slice to the input end - otherwise extracted file
        # will be truncated
        yield (buf_start_offset, 0) 
開發者ID:QubesOS,項目名稱:qubes-core-admin,代碼行數:39,代碼來源:tarwriter.py

示例3: test_eof_marker

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import BLOCKSIZE [as 別名]
def test_eof_marker(self):
        # Make sure an end of archive marker is written (two zero blocks).
        # tarfile insists on aligning archives to a 20 * 512 byte recordsize.
        # So, we create an archive that has exactly 10240 bytes without the
        # marker, and has 20480 bytes once the marker is written.
        with tarfile.open(tmpname, self.mode) as tar:
            t = tarfile.TarInfo("foo")
            t.size = tarfile.RECORDSIZE - tarfile.BLOCKSIZE
            tar.addfile(t, io.BytesIO(b"a" * t.size))

        with self.open(tmpname, "rb") as fobj:
            self.assertEqual(len(fobj.read()), tarfile.RECORDSIZE * 2) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:test_tarfile.py

示例4: addfile

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import BLOCKSIZE [as 別名]
def addfile(self, tarinfo, fileobj=None):
        """
        Add the provided fileobj to the tar using md5copyfileobj
        and saves the file md5 in the provided ChecksumTarInfo object.

        This method completely replaces TarFile.addfile()
        """
        self._check("aw")

        tarinfo = copy.copy(tarinfo)

        buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
        self.fileobj.write(buf)
        self.offset += len(buf)

        # If there's data to follow, append it.
        if fileobj is not None:
            tarinfo.data_checksum = md5copyfileobj(
                fileobj, self.fileobj, tarinfo.size)
            blocks, remainder = divmod(tarinfo.size, tarfile.BLOCKSIZE)
            if remainder > 0:
                self.fileobj.write(
                    tarfile.NUL * (tarfile.BLOCKSIZE - remainder))
                blocks += 1
            self.offset += blocks * tarfile.BLOCKSIZE

        self.members.append(tarinfo) 
開發者ID:2ndquadrant-it,項目名稱:barman,代碼行數:29,代碼來源:walarchive.py

示例5: addfile

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import BLOCKSIZE [as 別名]
def addfile(self, tarinfo, fileobj=None):
        """
        Add the provided fileobj to the tar ignoring truncated or vanished
        files.

        This method completely replaces TarFile.addfile()
        """
        self._check("awx")

        tarinfo = copy.copy(tarinfo)

        buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
        self.fileobj.write(buf)
        self.offset += len(buf)

        # If there's data to follow, append it.
        if fileobj is not None:
            copyfileobj_pad_truncate(fileobj, self.fileobj, tarinfo.size)
            blocks, remainder = divmod(tarinfo.size, tarfile.BLOCKSIZE)
            if remainder > 0:
                self.fileobj.write(
                    tarfile.NUL * (tarfile.BLOCKSIZE - remainder))
                blocks += 1
            self.offset += blocks * tarfile.BLOCKSIZE

        self.members.append(tarinfo) 
開發者ID:2ndquadrant-it,項目名稱:barman,代碼行數:28,代碼來源:cloud.py

示例6: tarfile_write_padding

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import BLOCKSIZE [as 別名]
def tarfile_write_padding(tarfd, sz):
    blocks, remainder = divmod(sz, tarfile.BLOCKSIZE)
    if remainder > 0:
        tarfd.fileobj.write("\0" * (tarfile.BLOCKSIZE - remainder))
        blocks += 1
    tarfd.offset += blocks * tarfile.BLOCKSIZE
    assert tarfd.offset == tarfd.fileobj.tell()


# Exception interrupts stream processing, tail of the stream can't be recovered.
# Single blob may be malformed, but it's out of blob parser control. 
開發者ID:ooni,項目名稱:pipeline,代碼行數:13,代碼來源:autoclaving.py

示例7: process_tarfd

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import BLOCKSIZE [as 別名]
def process_tarfd(l, tarfd):
    for tin, blob in l:
        tin.size = len(blob)
        tarfd.addfile(tin)

        # copy-paste from tarfile.addfile
        tarfd.fileobj.write(blob)
        blocks, remainder = divmod(len(blob), tarfile.BLOCKSIZE)
        if remainder > 0:
            tarfd.fileobj.write('\0' * (tarfile.BLOCKSIZE - remainder))
            blocks += 1
        tarfd.offset += blocks * tarfile.BLOCKSIZE 
開發者ID:ooni,項目名稱:pipeline,代碼行數:14,代碼來源:tarfile_write.py


注:本文中的tarfile.BLOCKSIZE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。