diff -rupbN -x 'cscope.*' -x autom4te.cache -x configure wget-1.14-rev1/src/ftp.c wget-1.14-rev2/src/ftp.c
--- wget-1.14-rev1/src/ftp.c	2013-10-02 16:49:09.318436000 -0700
+++ wget-1.14-rev2/src/ftp.c	2013-10-02 16:48:56.734436000 -0700
@@ -1263,7 +1263,8 @@ Error in server response, closing contro
   rd_size = 0;
   res = fd_read_body (dtsock, fp,
                       expected_bytes ? expected_bytes - restval : 0,
-                      restval, &rd_size, qtyread, &con->dltime, flags, warc_tmp);
+                      restval, &rd_size, qtyread, &con->dltime, flags,
+                      0, warc_tmp);
 
   tms = datetime_str (time (NULL));
   tmrate = retr_rate (rd_size, con->dltime);
diff -rupbN -x 'cscope.*' -x autom4te.cache -x configure wget-1.14-rev1/src/http.c wget-1.14-rev2/src/http.c
--- wget-1.14-rev1/src/http.c	2013-10-02 16:49:09.322436000 -0700
+++ wget-1.14-rev2/src/http.c	2013-10-02 16:48:56.742436000 -0700
@@ -1519,7 +1519,8 @@ static int
 read_response_body (struct http_stat *hs, int sock, FILE *fp, wgint contlen,
                     wgint contrange, bool chunked_transfer_encoding,
                     char *url, char *warc_timestamp_str, char *warc_request_uuid,
-                    ip_address *warc_ip, char *type, int statcode, char *head)
+	                  ip_address *warc_ip, char *type, int statcode, char *head,
+                    bool gzipped_resp)
 {
   int warc_payload_offset = 0;
   FILE *warc_tmp = NULL;
@@ -1580,7 +1581,7 @@ read_response_body (struct http_stat *hs
      response body to warc_tmp.  */
   hs->res = fd_read_body (sock, fp, contlen != -1 ? contlen : 0,
                           hs->restval, &hs->rd_size, &hs->len, &hs->dltime,
-                          flags, warc_tmp);
+                          flags, gzipped_resp, warc_tmp);
   if (hs->res >= 0)
     {
       if (warc_tmp != NULL)
@@ -1625,46 +1626,43 @@ read_response_body (struct http_stat *hs
 }
 
 #ifdef HAVE_GZIP
-static uerr_t decompress_file(char *file)
+/* this code adapted from http://www.zlib.net/zlib_how.html */
+#define CHUNK	4096
+z_stream zstrm;
+uerr_t decompress_data(char *inp, unsigned int in_len, FILE *outf)
 {
-	static char buf[4096];
-	char tmpf[] = "fnXXXXXX";
-	int nr, _nr, nw, tf, err;
-	gzFile zf;
+	int ret;
+	unsigned have;
+	unsigned char out[CHUNK];
 
-	tf = mkstemp(tmpf);
-	if (tf < 0)
-		return FOPENERR;
-	zf = gzopen(file, "rb");
-	if (zf == NULL) {
-		logprintf(LOG_NOTQUIET, "gzopen: %s, file: %s\n", strerror(errno), tmpf);
-		return GZOPENERR;
-	}
-	nr = 0;
-	while (1) {
-		_nr = gzread(zf, (void *)buf, sizeof(buf));
-		if (_nr == 0)
-			break;
-		if (_nr < 0) {
-			logprintf(LOG_NOTQUIET, "gzread: %s\n", strerror(errno));
-			return GZREADERR;
-		}
-		nr += _nr;
-		nw = write(tf, buf, _nr);
-		if (nw < _nr) {
-			logprintf(LOG_NOTQUIET, "fwrite: %s\n", strerror(errno));
-			return FWRITEERR;
-		}
-	}
-	close(tf);
-	gzclose(zf);
-	err = rename(tmpf, file);
-	if (err != 0) {
-		logprintf(LOG_NOTQUIET, "rename %s -> %s: %s\n", tmpf, file, strerror(errno));
-		return RENAMEERR;
+	if (in_len == 0)
+		return Z_OK;
+	zstrm.avail_in = in_len;
+	zstrm.next_in = inp;
+
+	do {
+		zstrm.avail_out = CHUNK;
+		zstrm.next_out = out;
+		ret = inflate(&zstrm, Z_NO_FLUSH);
+		assert(ret != Z_STREAM_ERROR);
+		switch (ret) {
+		case Z_NEED_DICT:
+			ret = Z_DATA_ERROR;
+		case Z_DATA_ERROR:
+		case Z_MEM_ERROR:
+			(void)inflateEnd(&zstrm);
+			return ret;
+		}
+		have = CHUNK - zstrm.avail_out;
+		if (fwrite(out, 1, have, outf) != have || ferror(outf)) {
+			(void)inflateEnd(&zstrm);
+			return Z_ERRNO;
 	}
-	return 0;
+	} while (zstrm.avail_out == 0);
+
+	return Z_OK;
 }
+#undef CHUNK
 #endif
 
 
@@ -2352,8 +2350,22 @@ read_header:
 #ifdef HAVE_GZIP
   gzipped_resp = false;
   if (resp_header_copy (resp, "Content-Encoding", hdrval, sizeof (hdrval))
-      && 0 == strcasecmp (hdrval, "gzip"))
+	      && 0 == strcasecmp (hdrval, "gzip")) {
+	  int ret;
 	  gzipped_resp = true;
+	  /* allocate inflate state */
+	  zstrm.zalloc = Z_NULL;
+	  zstrm.zfree = Z_NULL;
+	  zstrm.opaque = Z_NULL;
+	  zstrm.avail_in = 0;
+	  zstrm.next_in = Z_NULL;
+	  /* has to be 16 or more for gzip stream support
+	   * http://stackoverflow.com/questions/1838699/how-can-i-decompress-a-gzip-stream-with-zlib
+	   */
+	  ret = inflateInit2(&zstrm, 16+MAX_WBITS);
+	  if (ret != Z_OK)
+		  return ret;
+  }
 #endif
 
   /* Handle (possibly multiple instances of) the Set-Cookie header. */
@@ -2393,7 +2405,7 @@ read_header:
                                     chunked_transfer_encoding,
                                     u->url, warc_timestamp_str,
                                     warc_request_uuid, warc_ip, type,
-                                    statcode, head);
+	                                   statcode, head, gzipped_resp);
           xfree_null (type);
 
           if (err != RETRFINISHED || hs->res < 0)
@@ -2681,7 +2693,7 @@ read_header:
                                             chunked_transfer_encoding,
                                             u->url, warc_timestamp_str,
                                             warc_request_uuid, warc_ip, type,
-                                            statcode, head);
+                                            statcode, head, gzipped_resp);
 
               if (err != RETRFINISHED || hs->res < 0)
                 {
@@ -2837,7 +2849,7 @@ read_header:
                                         chunked_transfer_encoding,
                                         u->url, warc_timestamp_str,
                                         warc_request_uuid, warc_ip, type,
-                                        statcode, head);
+                                        statcode, head, gzipped_resp);
 
           if (err != RETRFINISHED || hs->res < 0)
             {
@@ -2966,14 +2978,7 @@ read_header:
                             chunked_transfer_encoding,
                             u->url, warc_timestamp_str,
                             warc_request_uuid, warc_ip, type,
-                            statcode, head);
-  if (gzipped_resp && err == RETRFINISHED) {
-	  int ret;
-
-	  ret = decompress_file(hs->local_file);
-	  if (ret)
-		  err = ret;
-  }
+	                           statcode, head, gzipped_resp);
 
   /* Now we no longer need to store the response header. */
   xfree (head);
diff -rupbN -x 'cscope.*' -x autom4te.cache -x configure wget-1.14-rev1/src/http.h wget-1.14-rev2/src/http.h
--- wget-1.14-rev1/src/http.h	2013-10-02 16:49:09.322436000 -0700
+++ wget-1.14-rev2/src/http.h	2013-10-02 16:48:56.734436000 -0700
@@ -31,6 +31,8 @@ as that of the covered work.  */
 #ifndef HTTP_H
 #define HTTP_H
 
+#include <zlib.h>
+
 struct url;
 
 uerr_t http_loop (struct url *, struct url *, char **, char **, const char *,
@@ -39,6 +41,9 @@ void save_cookies (void);
 void http_cleanup (void);
 time_t http_atotm (const char *);
 
+extern z_stream zstrm;
+uerr_t decompress_data(char *, unsigned int, FILE *);
+
 typedef struct {
   /* A token consists of characters in the [b, e) range. */
   const char *b, *e;
diff -rupbN -x 'cscope.*' -x autom4te.cache -x configure wget-1.14-rev1/src/init.c wget-1.14-rev2/src/init.c
--- wget-1.14-rev1/src/init.c	2013-10-02 16:49:09.322436000 -0700
+++ wget-1.14-rev2/src/init.c	2013-10-02 16:48:56.734436000 -0700
@@ -1686,6 +1686,7 @@ cleanup (void)
 
   log_close ();
 
+  inflateEnd(&zstrm);
   if (output_stream)
     if (fclose (output_stream) == EOF)
       inform_exit_status (CLOSEFAILED);
diff -rupbN -x 'cscope.*' -x autom4te.cache -x configure wget-1.14-rev1/src/main.c wget-1.14-rev2/src/main.c
--- wget-1.14-rev1/src/main.c	2013-10-02 14:20:56.094436000 -0700
+++ wget-1.14-rev2/src/main.c	2013-10-02 16:53:21.214436000 -0700
@@ -234,7 +234,7 @@ static struct cmdline_option option_data
     { "mirror", 'm', OPT_BOOLEAN, "mirror", -1 },
     { "no", 'n', OPT__NO, NULL, required_argument },
 #ifdef HAVE_GZIP
-    { "no-ae-gzip", 'z', OPT_BOOLEAN, "noaegzip", -1 },
+    { "no-accept-encoding-gzip", 0, OPT_BOOLEAN, "noaegzip", -1 },
 #endif
     { "no-clobber", 0, OPT_BOOLEAN, "noclobber", -1 },
     { "no-parent", 0, OPT_BOOLEAN, "noparent", -1 },
diff -rupbN -x 'cscope.*' -x autom4te.cache -x configure wget-1.14-rev1/src/Makefile.am wget-1.14-rev2/src/Makefile.am
--- wget-1.14-rev1/src/Makefile.am	2013-10-02 16:49:09.314436000 -0700
+++ wget-1.14-rev2/src/Makefile.am	2013-10-02 16:48:56.734436000 -0700
@@ -82,7 +82,7 @@ version.c:  $(wget_SOURCES) ../lib/libgn
 	    | $(ESCAPEQUOTE) >> $@
 
 css.c: $(srcdir)/css.l
-	$(LEX) $(LFLAGS) -o $@ $^
+	$(LEX) $(LFLAGS) -o$@ $^
 
 css_.c: css.c
 	echo '#include "wget.h"' > $@
diff -rupbN -x 'cscope.*' -x autom4te.cache -x configure wget-1.14-rev1/src/retr.c wget-1.14-rev2/src/retr.c
--- wget-1.14-rev1/src/retr.c	2013-10-02 16:49:09.326436000 -0700
+++ wget-1.14-rev2/src/retr.c	2013-10-02 16:48:56.734436000 -0700
@@ -146,7 +146,7 @@ limit_bandwidth (wgint bytes, struct pti
 
 static int
 write_data (FILE *out, FILE *out2, const char *buf, int bufsize,
-            wgint *skip, wgint *written)
+			wgint *skip, wgint *written, bool gzipped_resp)
 {
   if (out == NULL && out2 == NULL)
     return 1;
@@ -164,8 +164,14 @@ write_data (FILE *out, FILE *out2, const
         return 1;
     }
 
-  if (out != NULL)
+  if (out != NULL) {
+	  if (gzipped_resp) {
+		  if (decompress_data(buf, bufsize, out) != Z_OK)
+			  return -3;
+	  }
+	  else
     fwrite (buf, 1, bufsize, out);
+  }
   if (out2 != NULL)
     fwrite (buf, 1, bufsize, out2);
   *written += bufsize;
@@ -225,7 +231,7 @@ write_data (FILE *out, FILE *out2, const
 int
 fd_read_body (int fd, FILE *out, wgint toread, wgint startpos,
               wgint *qtyread, wgint *qtywritten, double *elapsed, int flags,
-              FILE *out2)
+              bool gzipped_resp, FILE *out2)
 {
   int ret = 0;
 #undef max
@@ -375,7 +381,7 @@ fd_read_body (int fd, FILE *out, wgint t
       if (ret > 0)
         {
           sum_read += ret;
-          int write_res = write_data (out, out2, dlbuf, ret, &skip, &sum_written);
+          int write_res = write_data (out, out2, dlbuf, ret, &skip, &sum_written, gzipped_resp);
           if (write_res != 0)
             {
               ret = (write_res == -3) ? -3 : -2;
diff -rupbN -x 'cscope.*' -x autom4te.cache -x configure wget-1.14-rev1/src/retr.h wget-1.14-rev2/src/retr.h
--- wget-1.14-rev1/src/retr.h	2013-10-02 16:49:09.326436000 -0700
+++ wget-1.14-rev2/src/retr.h	2013-10-02 16:48:56.742436000 -0700
@@ -50,7 +50,7 @@ enum {
   rb_chunked_transfer_encoding = 4
 };
 
-int fd_read_body (int, FILE *, wgint, wgint, wgint *, wgint *, double *, int, FILE *);
+int fd_read_body (int, FILE *, wgint, wgint, wgint *, wgint *, double *, int, bool, FILE *);
 
 typedef const char *(*hunk_terminator_t) (const char *, const char *, int);
 
