From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Magne Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: Mysterious gzipped images Date: Thu, 08 Aug 2013 12:35:49 +0200 Message-ID: References: <87mwoul8sz.fsf@igel.home> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1375958178 15696 80.91.229.3 (8 Aug 2013 10:36:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 8 Aug 2013 10:36:18 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 08 12:36:21 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V7NZs-0004Qk-N5 for ged-emacs-devel@m.gmane.org; Thu, 08 Aug 2013 12:36:20 +0200 Original-Received: from localhost ([::1]:36240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7NZs-0007LE-4X for ged-emacs-devel@m.gmane.org; Thu, 08 Aug 2013 06:36:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7NZk-00079h-Kq for emacs-devel@gnu.org; Thu, 08 Aug 2013 06:36:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V7NZg-0007uH-1x for emacs-devel@gnu.org; Thu, 08 Aug 2013 06:36:12 -0400 Original-Received: from hermes.netfonds.no ([80.91.224.195]:50575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7NZf-0007rn-Os for emacs-devel@gnu.org; Thu, 08 Aug 2013 06:36:08 -0400 Original-Received: from cm-84.215.51.58.getinternet.no ([84.215.51.58] helo=stories.gnus.org) by hermes.netfonds.no with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1V7NZN-0003IE-Cb; Thu, 08 Aug 2013 12:35:49 +0200 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAHlBMVEUAAAAAAAMFBQ0BAwkA AAS6fXwICA8AAQY2Eh8AAQcETrc+AAACLElEQVQ4jW2TQaucMBDHtS286wrC0muWyuuxpuySWy2B 4AcQPG9pcG/dViq5FpTc80Dm23YmE2UfvCAK+fn/z0wyk2VxHQqtx6J0YSwO+VEGKbNDBLnW5t44 UOpeFK0iwKsw07ROgBtrOQEqTgmUZpwAVwBoDEi1W5VmcmFFKwDtULeBvCxNCy8QCIB8BSYHawTw CLK8+W5p3eB8sp/JK/sWy8ibT7PvfbeA1h9lCLJmgGXg79equsJLcwRMqo5WT7Xd1lWcRgJc4O8q bQ8LvkTMN4I6gcFHUUyYQRJ470liHCQgNgETtqLgu1PXdf1iHYRHIOzz3NFajKN0dythh7jf9SOG EAxIIgQLuu4GW3COkQQIMKvTG6C/QXiV7gNQtXgD+EvYgierFNyTk411kGKwlkFvEdR2L3D2SwRU uSTQICCjrvd+ToAVB1aQ+bxbYYyGwbCDbsE7r7fgHg8We6FnIOXZxnTPP8mCIH0IVDZ2yV/O3/P7 HysKBO9m3pq7GXU/GLxPnTgNlDS1NV1sCk4DovH32TuAF8fgnh94cmIr0By0j4q8OPoEFDBo0uSU LajJKYlTFR4VZenU2rT7eFQ7wJNbtYtjGCL48yWCo8O51DjIrKmr7Cun+zRNsDYmqJUEtRAbKPUR VoxzWUmBXZ7dN2CwN5TCdFsVwaZAF+XwJpSKV26zXww0HoQasQ4sPdTYs5wsPkZCi+nWynH07RA/ OLhcsAwJ1AqY1X/rL0NxGDWE/wAAAABJRU5ErkJggg== X-Now-Playing: Joni Mitchell's _Shadows And Light (1)_: "The Dry Cleaner From Des Moines" X-Hashcash: 1:23:130808:monnier@iro.umontreal.ca::NGYJDQWVZJ55w3Km:00000000000000000000000000000000000003rQv X-Hashcash: 1:23:130808:emacs-devel@gnu.org::DfAXBg9/pCSYxdpR:000000000000000000000000000000000000000000Aq9x In-Reply-To: (Stefan Monnier's message of "Wed, 07 Aug 2013 10:35:54 -0400") User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux) X-MailScanner-ID: 1V7NZN-0003IE-Cb MailScanner-NULL-Check: 1376562949.60466@a9dtSVxWO5Aw/nCo/7Fv7g X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.224.195 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:162487 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: > So curl doesn't implement Accept/Content-Encoding either? That's weird! It does, but you have to say "curl --compressed". That makes curl both say that it accept gzipped content and decompresses it if it gets it. Although it's "wrong" for the server to output compressed data if the client doesn't say that it accepts it, I think it's pretty buggy not to decode the compressed data, anyway. > Sounds good, tho I'd prefer to see the patch first. I've included the new .c file below. The attendant code change to lisp.h/emacs.c is what you'd expect. Now I just have to write the configure.ac code to define HAVE_ZLIB. --=-=-= Content-Type: text/x-csrc Content-Disposition: inline; filename=decompress.c /* Interface to zlib. Copyright (C) 2013 Free Software Foundation, Inc. This file is part of GNU Emacs. GNU Emacs is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ #include #ifdef HAVE_PNG #include #include "lisp.h" #include "character.h" #include "buffer.h" #define BUFFER_SIZE 16384 DEFUN ("decompress-gzipped-region", Fdecompress_gzipped_region, Sdecompress_gzipped_region, 2, 2, 0, doc: /* Decompress a gzip-compressed region. The text in the region will be replaced by the decompressed data. On failure, nil is returned and the data is left in place. This function can only be called in unibyte buffers.*/) (Lisp_Object start, Lisp_Object end) { ptrdiff_t istart, iend, point = PT; z_stream stream; int decompressed; unsigned char *out; validate_region (&start, &end); move_gap_both (iend, iend); if (! NILP (BVAR (current_buffer, enable_multibyte_characters))) error ("This function can only be called in unibyte buffers"); /* This is a unibyte buffer, so character positions and bytes are the same. */ istart = XINT (start); iend = XINT (end); stream.zalloc = Z_NULL; stream.zfree = Z_NULL; stream.opaque = Z_NULL; stream.avail_in = 0; stream.next_in = Z_NULL; /* This magic number apparently means "this is gzip". */ if (inflateInit2 (&stream, 16 + MAX_WBITS) != Z_OK) return Qnil; out = (char *) malloc (BUFFER_SIZE); /* We're inserting the decompressed data at the end of the compressed data. */ SET_PT (iend); stream.avail_in = iend - istart; stream.next_in = (char *) BYTE_POS_ADDR (istart); /* Run inflate() on input until the output buffer isn't full. */ do { stream.avail_out = BUFFER_SIZE; stream.next_out = out; switch (inflate (&stream, Z_NO_FLUSH)) { case Z_STREAM_ERROR: case Z_NEED_DICT: case Z_DATA_ERROR: case Z_MEM_ERROR: inflateEnd (&stream); /* Delete any uncompressed data already inserted and restore point. */ del_range (iend, PT); SET_PT (point); free (out); return Qnil; } decompressed = BUFFER_SIZE - stream.avail_out; insert_1_both (out, decompressed, decompressed, 0, 0, 0); } while (stream.avail_out == 0); inflateEnd (&stream); free (out); /* Delete the compressed data. */ del_range (istart, iend); return Qt; } /*********************************************************************** Initialization ***********************************************************************/ void syms_of_decompress (void) { defsubr (&Sdecompress_gzipped_region); } #endif /* HAVE_PNG */ --=-=-= Content-Type: text/plain -- (domestic pets only, the antidote for overdose, milk.) No Gnus T-Shirt for sale: http://ingebrigtsen.no/no.php and http://lars.ingebrigtsen.no/2013/08/twenty-years-of-september.html --=-=-=--