{"id":1088,"date":"2013-08-31T10:58:11","date_gmt":"2013-08-31T10:58:11","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=1088"},"modified":"2013-08-31T13:14:48","modified_gmt":"2013-08-31T13:14:48","slug":"zlib-simple-example-gzseek","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2013\/08\/zlib-simple-example-gzseek\/","title":{"rendered":"zlib simple example (gzseek)"},"content":{"rendered":"<p>Very simple zlib example. The neat thing is that zlib is transparent to uncompressed files, so you can just replace all your file seeking with zlib code and it&#8217;ll work with compressed and uncompressed code. It&#8217;s worth noting that gzseek does not support SEEK_END, which can cause issues.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\r\n#include &lt;zlib.h&gt;\r\n#include &lt;stdio.h&gt;\r\n\r\nint main() {\r\n  gzFile file = gzopen(&quot;test.gz&quot;, &quot;rb&quot;);\r\n  if(file == NULL) {\r\n    fprintf(stderr, &quot;gzopen error\\n&quot;);\r\n  }\r\n\r\n  char buffer&#x5B;1000];\r\n  int uncomprLen = gzread(file, buffer, 1000);\r\n  buffer&#x5B;uncomprLen]=0;\r\n  printf(&quot;data: %s\\n&quot;,buffer);  \r\n\r\n  int pos = gzseek(file, 5, SEEK_SET);\r\n  \r\n  uncomprLen = gzread(file, buffer, 5);\r\n  buffer&#x5B;6]=0;\r\n  printf(&quot;data: %s\\n&quot;,buffer);  \r\n\r\n  gzclose(file);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Very simple zlib example. The neat thing is that zlib is transparent to uncompressed files, so you can just replace all your file seeking with zlib code and it&#8217;ll work with compressed and uncompressed code. It&#8217;s worth noting that gzseek does not support SEEK_END, which can cause issues. #include &lt;zlib.h&gt; #include &lt;stdio.h&gt; int main() { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-1088","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-hy","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/1088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=1088"}],"version-history":[{"count":4,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/1088\/revisions"}],"predecessor-version":[{"id":1092,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/1088\/revisions\/1092"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=1088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=1088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=1088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}