<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](gzip.xhtml "gzip --- 對 gzip 格式的支持") | - [上一頁](archiving.xhtml "數據壓縮和存檔") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 標準庫](index.xhtml) ? - [數據壓縮和存檔](archiving.xhtml) ? - $('.inline-search').show(0); | # [`zlib`](#module-zlib "zlib: Low-level interface to compression and decompression routines compatible with gzip.") --- 與 **gzip** 兼容的壓縮 - - - - - - 此模塊為需要數據壓縮的程序提供了一系列函數,用于壓縮和解壓縮。這些函數使用了 zlib 庫。zlib 庫的項目主頁是 <http://www.zlib.net>. 版本低于 1.1.3 的 zlib 與此 Python 模塊之間存在已知的不兼容。1.1.3 版本的 zlib 存在一個安全漏洞,我們推薦使用 1.1.4 或更新的版本。 zlib 的函數有很多選項,一般需要按特定順序使用。本文檔沒有覆蓋全部的用法。更多詳細信息請于 <http://www.zlib.net/manual.html> 參閱官方手冊。 要讀寫 `.gz` 格式的文件,請參考 [`gzip`](gzip.xhtml#module-gzip "gzip: Interfaces for gzip compression and decompression using file objects.") 模塊。 此模塊中可用的異常和函數如下: *exception* `zlib.``error`在壓縮或解壓縮過程中發生錯誤時的異常。 `zlib.``adler32`(*data*\[, *value*\])計算 *data* 的 Adler-32 校驗值。(Adler-32 校驗的可靠性與 CRC32 基本相當,但比計算 CRC32 更高效。) 計算的結果是一個 32 位的整數。參數 *value* 是校驗時的起始值,其默認值為 1。借助參數 *value* 可為分段的輸入計算校驗值。此算法沒有加密強度,不應用于身份驗證和數字簽名。此算法的目的僅為驗證數據的正確性,不適合作為通用散列算法。 在 3.0 版更改: 返回值永遠是無符號數。要在所有的 Python 版本和平臺上獲得相同的值,請使用 `adler32(data) & 0xffffffff`。 `zlib.``compress`(*data*, *level=-1*)壓縮 *data* 中的字節,返回含有已壓縮內容的 bytes 對象。參數 *level* 為整數,可取值為 `0` 到 `9` 或 `-1`,用于指定壓縮等級。`1` (Z\_BEST\_SPEED) 表示最快速度和最低壓縮率,`9` (Z\_BEST\_COMPRESSION) 表示最慢速度和最高壓縮率。`0` (Z\_NO\_COMPRESSION) 表示不壓縮。參數默認值為 `-1` (Z\_DEFAULT\_COMPRESSION)。Z\_DEFAULT\_COMPRESSION 是速度和壓縮率之間的平衡 (一般相當于設壓縮等級為 6)。函數發生錯誤時拋出 [`error`](#zlib.error "zlib.error") 異常。 在 3.6 版更改: 現在,*level* 可作為關鍵字參數。 `zlib.``compressobj`(*level=-1*, *method=DEFLATED*, *wbits=MAX\_WBITS*, *memLevel=DEF\_MEM\_LEVEL*, *strategy=Z\_DEFAULT\_STRATEGY*\[, *zdict*\])返回一個 壓縮對象,用來壓縮內存中難以容下的數據流。 參數 *level* 為壓縮等級,是整數,可取值為 `0` 到 `9` 或 `-1`。`1` (Z\_BEST\_SPEED) 表示最快速度和最低壓縮率,`9` (Z\_BEST\_COMPRESSION) 表示最慢速度和最高壓縮率。`0` (Z\_NO\_COMPRESSION) 表示不壓縮。參數默認值為 `-1` (Z\_DEFAULT\_COMPRESSION)。Z\_DEFAULT\_COMPRESSION 是速度和壓縮率之間的平衡 (一般相當于設壓縮等級為 6)。 *method* 表示壓縮算法。現在只支持 `DEFLATED` 這個算法。 參數 *wbits* 指定壓縮數據時所使用的歷史緩沖區的大小 (窗口大小),并指定壓縮輸出是否包含頭部或尾部。參數的默認值是 `15` (MAX\_WBITS)。參數的值分為幾個范圍: - +9 到 +15:窗口大小以 2 為底的對數。即這些值對應著 512 到 32768 的窗口大小。更大的值會提供更好的壓縮,同時內存開銷也會更大。壓縮輸出會包含 zlib 特定格式的頭部和尾部。 - ?9 到 ?15:絕對值為窗口大小以 2 為底的對數。壓縮輸出僅包含壓縮數據,沒有頭部和尾部。 - +25 到 +31 = 16 + (9 到 15):后 4 個比特位為窗口大小以 2 為底的對數。壓縮輸出包含一個基本的 **gzip** 頭部,并以校驗和為尾部。 參數 *memLevel* 指定內部壓縮操作時所占用內存大小。參數取 `1` 到 `9`。更大的值占用更多的內存,同時速度也更快輸出也更小。 參數 *strategy* 用于調節壓縮算法。可取值為 `Z_DEFAULT_STRATEGY`、`Z_FILTERED`、`Z_HUFFMAN_ONLY`、`Z_RLE` (zlib 1.2.0.1) 或 `Z_FIXED` (zlib 1.2.2.2)。 參數 *zdict* 指定預定義的壓縮字典。它是一個字節序列 (如 [`bytes`](stdtypes.xhtml#bytes "bytes") 對象),其中包含用戶認為要壓縮的數據中可能頻繁出現的子序列。頻率高的子序列應當放在字典的尾部。 在 3.3 版更改: 添加關鍵字參數 *zdict*。 `zlib.``crc32`(*data*\[, *value*\])計算 *data* 的 CRC (循環冗余校驗) 值。計算的結果是一個 32 位的整數。參數 *value* 是校驗時的起始值,其默認值為 0。借助參數 *value* 可為分段的輸入計算校驗值。此算法沒有加密強度,不應用于身份驗證和數字簽名。此算法的目的僅為驗證數據的正確性,不適合作為通用散列算法。 在 3.0 版更改: 返回值永遠是無符號數。要在所有的 Python 版本和平臺上獲得相同的值,請使用 `crc32(data) & 0xffffffff`。 `zlib.``decompress`(*data*, *wbits=MAX\_WBITS*, *bufsize=DEF\_BUF\_SIZE*)解壓 *data* 中的字節,返回含有已解壓內容的 bytes 對象。參數 *wbits* 取決于 *data* 的格式,具體參見下邊的說明。*bufsize* 為輸出緩沖區的起始大小。函數發生錯誤時拋出 [`error`](#zlib.error "zlib.error") 異常。 The *wbits* parameter controls the size of the history buffer (or "window size"), and what header and trailer format is expected. It is similar to the parameter for [`compressobj()`](#zlib.compressobj "zlib.compressobj"), but accepts more ranges of values: - +8 to +15: The base-two logarithm of the window size. The input must include a zlib header and trailer. - 0: Automatically determine the window size from the zlib header. Only supported since zlib 1.2.3.5. - ?8 to ?15: Uses the absolute value of *wbits* as the window size logarithm. The input must be a raw stream with no header or trailer. - +24 to +31 = 16 + (8 to 15): Uses the low 4 bits of the value as the window size logarithm. The input must include a gzip header and trailer. - +40 to +47 = 32 + (8 to 15): Uses the low 4 bits of the value as the window size logarithm, and automatically accepts either the zlib or gzip format. When decompressing a stream, the window size must not be smaller than the size originally used to compress the stream; using a too-small value may result in an [`error`](#zlib.error "zlib.error") exception. The default *wbits* value corresponds to the largest window size and requires a zlib header and trailer to be included. *bufsize* is the initial size of the buffer used to hold decompressed data. If more space is required, the buffer size will be increased as needed, so you don't have to get this value exactly right; tuning it will only save a few calls to `malloc()`. 在 3.6 版更改: *wbits* and *bufsize* can be used as keyword arguments. `zlib.``decompressobj`(*wbits=MAX\_WBITS*\[, *zdict*\])Returns a decompression object, to be used for decompressing data streams that won't fit into memory at once. The *wbits* parameter controls the size of the history buffer (or the "window size"), and what header and trailer format is expected. It has the same meaning as [described for decompress()](#decompress-wbits). The *zdict* parameter specifies a predefined compression dictionary. If provided, this must be the same dictionary as was used by the compressor that produced the data that is to be decompressed. 注解 If *zdict* is a mutable object (such as a [`bytearray`](stdtypes.xhtml#bytearray "bytearray")), you must not modify its contents between the call to [`decompressobj()`](#zlib.decompressobj "zlib.decompressobj") and the first call to the decompressor's `decompress()` method. 在 3.3 版更改: Added the *zdict* parameter. 壓縮對象支持以下方法: `Compress.``compress`(*data*)壓縮 *data* 并返回 bytes 對象,這個對象含有 *data* 的部分或全部內容的已壓縮數據。所得的對象必須拼接在上一次調用 [`compress()`](#zlib.compress "zlib.compress") 方法所得數據的后面。緩沖區中可能留存部分輸入以供下一次調用。 `Compress.``flush`(\[*mode*\])壓縮所有緩沖區的數據并返回已壓縮的數據。參數 *mode* 可以傳入的常量為:`Z_NO_FLUSH`、`Z_PARTIAL_FLUSH`、`Z_SYNC_FLUSH`、`Z_FULL_FLUSH`、`Z_BLOCK` (zlib 1.2.3.4) 或 `Z_FINISH`。默認值為 `Z_FINISH`。`Z_FINISH` 關閉已壓縮數據流并不允許再壓縮其他數據,`Z_FINISH` 以外的值皆允許這個對象繼續壓縮數據。調用 [`flush()`](#zlib.Compress.flush "zlib.Compress.flush") 方法并將 *mode* 設為 `Z_FINISH` 后會無法再次調用 [`compress()`](#zlib.compress "zlib.compress"),此時只能刪除這個對象。 `Compress.``copy`()返回此壓縮對象的一個拷貝。它可以用來高效壓縮一系列擁有相同前綴的數據。 解壓縮對象支持以下方法: `Decompress.``unused_data`A bytes object which contains any bytes past the end of the compressed data. That is, this remains `b""` until the last byte that contains compression data is available. If the whole bytestring turned out to contain compressed data, this is `b""`, an empty bytes object. `Decompress.``unconsumed_tail`A bytes object that contains any data that was not consumed by the last [`decompress()`](#zlib.decompress "zlib.decompress") call because it exceeded the limit for the uncompressed data buffer. This data has not yet been seen by the zlib machinery, so you must feed it (possibly with further data concatenated to it) back to a subsequent [`decompress()`](#zlib.decompress "zlib.decompress") method call in order to get correct output. `Decompress.``eof`A boolean indicating whether the end of the compressed data stream has been reached. This makes it possible to distinguish between a properly-formed compressed stream, and an incomplete or truncated one. 3\.3 新版功能. `Decompress.``decompress`(*data*, *max\_length=0*)Decompress *data*, returning a bytes object containing the uncompressed data corresponding to at least part of the data in *string*. This data should be concatenated to the output produced by any preceding calls to the [`decompress()`](#zlib.decompress "zlib.decompress") method. Some of the input data may be preserved in internal buffers for later processing. If the optional parameter *max\_length* is non-zero then the return value will be no longer than *max\_length*. This may mean that not all of the compressed input can be processed; and unconsumed data will be stored in the attribute [`unconsumed_tail`](#zlib.Decompress.unconsumed_tail "zlib.Decompress.unconsumed_tail"). This bytestring must be passed to a subsequent call to [`decompress()`](#zlib.decompress "zlib.decompress") if decompression is to continue. If *max\_length* is zero then the whole input is decompressed, and [`unconsumed_tail`](#zlib.Decompress.unconsumed_tail "zlib.Decompress.unconsumed_tail") is empty. 在 3.6 版更改: *max\_length* can be used as a keyword argument. `Decompress.``flush`(\[*length*\])All pending input is processed, and a bytes object containing the remaining uncompressed output is returned. After calling [`flush()`](#zlib.Decompress.flush "zlib.Decompress.flush"), the [`decompress()`](#zlib.decompress "zlib.decompress") method cannot be called again; the only realistic action is to delete the object. The optional parameter *length* sets the initial size of the output buffer. `Decompress.``copy`()Returns a copy of the decompression object. This can be used to save the state of the decompressor midway through the data stream in order to speed up random seeks into the stream at a future point. 通過下列常量可獲取模塊所使用的 zlib 庫的版本信息: `zlib.``ZLIB_VERSION`構建此模塊時所用的 zlib 庫的版本字符串。它的值可能與運行時所加載的 zlib 不同。運行時加載的 zlib 庫的版本字符串為 [`ZLIB_RUNTIME_VERSION`](#zlib.ZLIB_RUNTIME_VERSION "zlib.ZLIB_RUNTIME_VERSION")。 `zlib.``ZLIB_RUNTIME_VERSION`解釋器所加載的 zlib 庫的版本字符串。 3\.3 新版功能. 參見 模塊 [`gzip`](gzip.xhtml#module-gzip "gzip: Interfaces for gzip compression and decompression using file objects.")讀寫 **gzip** 格式的文件。 <http://www.zlib.net>zlib 庫項目主頁。 <http://www.zlib.net/manual.html>zlib 庫用戶手冊。提供了庫的許多功能的解釋和用法。 ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](gzip.xhtml "gzip --- 對 gzip 格式的支持") | - [上一頁](archiving.xhtml "數據壓縮和存檔") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 標準庫](index.xhtml) ? - [數據壓縮和存檔](archiving.xhtml) ? - $('.inline-search').show(0); | ? [版權所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 軟件基金會是一個非盈利組織。 [請捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [發現了問題](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 創建。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看