{"id":390,"date":"2009-12-10T11:30:06","date_gmt":"2009-12-10T17:30:06","guid":{"rendered":"http:\/\/www.ourada.org\/blog\/?p=390"},"modified":"2009-12-10T11:30:06","modified_gmt":"2009-12-10T17:30:06","slug":"asc-gzip-xfd-decompression","status":"publish","type":"post","link":"https:\/\/www.ourada.org\/blog\/archives\/390","title":{"rendered":"asc-gzip\/.xfd decompression"},"content":{"rendered":"<p>Scott Stafford was nice enough to post code for asc-gzip\/.xfd decompression to go with my asc-gzip\/.xfd compression code. See <a href=\"http:\/\/www.ourada.org\/blog\/archives\/375#comment-25551\">this comment<\/a>. I&#8217;m also reposting it here because the comment formatting is a little more bad than the main-post formatting.<\/p>\n<hr \/>\n<p>Thanks for your post.  Of course, I needed the opposite, I had one I needed to decompress.  So I backwarded your algorithm and here is the result:<\/p>\n<pre>\ndef decompress(fc):\n    fc2 = fc.splitlines(True)\n    fc3 = \"\".join(fc2[1:]) # could verify that it's asc-gzip here if we wanted to...\n    unb64 = base64.standard_b64decode(fc3)\n    \n    ctr = 0\n    ret = []\n    while 1:\n        if ctr == len(unb64): break\n        \n        ccltop = ord(unb64[ctr])\n        ctr += 1\n        cclbottom = ord(unb64[ctr])\n        ctr += 1\n        compressedchunklen = ccltop * 256 + cclbottom\n        \n        cltop = ord(unb64[ctr])\n        ctr += 1\n        clbottom = ord(unb64[ctr])\n        ctr += 1\n        chunklen = cltop * 256 + clbottom\n        #~ print compressedchunklen, chunklen\n        \n        compressedchunk = unb64[ctr:ctr+compressedchunklen]\n        ctr += compressedchunklen\n        \n        chunk = zlib.decompress(compressedchunk)\n        assert(len(chunk) ==  chunklen)\n        ret.append(chunk)\n    \n    return \"\".join(ret)\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Scott Stafford was nice enough to post code for asc-gzip\/.xfd decompression to go with my asc-gzip\/.xfd compression code. See this comment. I&#8217;m also reposting it here because the comment formatting is a little more bad than the main-post formatting. Thanks for your post. Of course, I needed the opposite, I had one I needed to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-390","post","type-post","status-publish","format-standard","hentry","category-general","author-admin"],"_links":{"self":[{"href":"https:\/\/www.ourada.org\/blog\/wp-json\/wp\/v2\/posts\/390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ourada.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ourada.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ourada.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ourada.org\/blog\/wp-json\/wp\/v2\/comments?post=390"}],"version-history":[{"count":0,"href":"https:\/\/www.ourada.org\/blog\/wp-json\/wp\/v2\/posts\/390\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ourada.org\/blog\/wp-json\/wp\/v2\/media?parent=390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ourada.org\/blog\/wp-json\/wp\/v2\/categories?post=390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ourada.org\/blog\/wp-json\/wp\/v2\/tags?post=390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}