{"id":187171,"date":"2020-10-30T19:06:58","date_gmt":"2020-10-30T11:06:58","guid":{"rendered":"http:\/\/4563.org\/?p=187171"},"modified":"2020-10-30T19:06:58","modified_gmt":"2020-10-30T11:06:58","slug":"zlib-compress-%e5%90%8e-decompress-%e5%be%97%e4%b8%8d%e5%88%b0%e5%8e%9f%e6%9d%a5%e7%9a%84%e5%86%85%e5%ae%b9%ef%bc%88-python-3-8%ef%bc%89","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=187171","title":{"rendered":"zlib compress \u540e decompress \u5f97\u4e0d\u5230\u539f\u6765\u7684\u5185\u5bb9\uff08 Python 3.8\uff09"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  zlib compress \u540e decompress \u5f97\u4e0d\u5230\u539f\u6765\u7684\u5185\u5bb9\uff08 Python 3.8\uff09               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wingkou <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>import zlib str1 = \"1234567890\" data1 = str1.encode() print(len(data1), data1.decode()) data2 = zlib.compressobj().compress(data1) data3 = zlib.decompressobj().decompress(data2) str2 = data3.decode() print(len(str2), str2) <\/code><\/pre>\n<p>\u6211\u8fd9\u91cc\u8f93\u51fa\u7684\u662f\uff1a<\/p>\n<pre><code>10 1234567890 0 <\/code><\/pre>\n<p>\u4e3a\u4ec0\u4e48\u4f1a\u8fd9\u6837\u7684\u5462\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4055663\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lcdtyph <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             (de)compressobj()\u8fd4\u56de\u7684\u5bf9\u8c61\u662f\u6709\u72b6\u6001\u7684\uff0c\u4e3b\u8981\u7528\u6765\u5904\u7406\u6d41\u6570\u636e\uff0c\u5728\u8f93\u5165\u7ed3\u675f\u4e4b\u540e\u8981\u8c03\u7528 obj.flush() \u6765\u63a5\u6536\u6700\u540e\u4e00\u6bb5\u8f93\u51fa<\/p>\n<p>\u5982\u679c\u662f\u4e00\u6b21\u6027\u538b\u7f29\u89e3\u538b\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528 zlib.compress \u3002\u5982\u679c\u4e00\u5b9a\u8981\u7528(de)compressobj \u53ef\u4ee5\u8fd9\u6837\uff1a<br \/>cobj = zlib.compressobj()<br \/>dobj = zlib.decmpressobj()<\/p>\n<p>data2 = cobj.compress(data1)<br \/>data2 += cobj.flush()<\/p>\n<p>data3 = dobj.decompress(data2)<br \/>data3 += dobj.flush()                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4055664\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wingkou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lcdtyph \u611f\u8c22\uff0c\u56e0\u4e3a\u6709\u4e2a\u6587\u4ef6\u76f4\u63a5`zlib.compress`\u4f1a\u62a5\u9519\uff0c\u4f46\u662f`zlib.decmpressobj().decompress()`\u5374\u4e0d\u4f1a\uff0c\u624d\u641e\u7684\u8fd9\u79cd\u5199\u6cd5\u3002\u8fd9\u95ee\u9898\u4e5f Google \u4e0d\u5230\uff0c\u5927\u534a\u591c\u8fd8\u641e\u5f97\u7126\u5934\u70c2\u989d\u7684\u3002\u4e0d\u77e5\u9053\u4f60\u77e5\u9053\u6709\u4ec0\u4e48\u533a\u522b\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4055665\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wingkou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lcdtyph \u4e0a\u9762\u6253\u5feb\u4e86\uff0c\u5e94\u8be5\u662f`zlib.decompress()`\u4f1a\u62a5\u9519\uff0c\u4f46\u662f`zlib.decmpressobj().decompress()`\u5374\u4e0d\u4f1a\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4055666\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : owtotwo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5efa\u8bae\u628a\u62a5\u9519\u7684 minimum \u6587\u4ef6\u6837\u4f8b\u4e5f\u5217\u51fa\u6765\uff0c\u4e0d\u7136\u4e0d\u597d\u590d\u73b0                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>zlib compress \u540e d&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/187171"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187171"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/187171\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187171"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}