--- dillo-0.7.2/src/IO/file.c.orig Sun May 4 12:33:54 2003 +++ dillo-0.7.2/src/IO/file.c Sun May 4 12:57:50 2003 @@ -29,6 +29,7 @@ #include #include #include /* for rint */ +#include #include /* for errno */ #include "Url.h" @@ -62,11 +63,12 @@ gint FD; /* Our local-file descriptor */ char *FileName; glong FileSize; + gint ContentEncoding; /* 0 normal, 1 gzipped */ pthread_t th1; /* This transfer's thread id. */ } DilloFile; - +#define GZIP_ENCODING 1 /* * Local data @@ -120,17 +122,28 @@ { gint fds[2], fd; struct stat sb; + gint ContentEncoding; /* 0 normal, 1 gzipped */ DilloFile *Dfile; - if ( (fd = open(filename, O_RDONLY)) < 0 || pipe(fds) ) + if ( (fd = open(filename, O_RDONLY)) < 0 || pipe(fds) ) { return NULL; - + } + if (strncmp(strrchr(filename, '.'), ".gz", 3) == 0) + ContentEncoding = GZIP_ENCODING; Dfile = g_new(DilloFile, 1); Dfile->FD_Read = fds[0]; Dfile->FD_Write = fds[1]; Dfile->FD = fd; Dfile->FileName = g_strdup(filename); - Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size; + if (ContentEncoding == GZIP_ENCODING) { + gchar *tmp_filename = g_strndup(filename, strlen(filename) - 3); + g_free(tmp_filename); + Dfile->FileSize = -1; + } + else { + Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size; + } + Dfile->ContentEncoding = ContentEncoding; return Dfile; } @@ -194,6 +207,7 @@ DilloFile *Dfile = data; ssize_t nbytes; const gchar *ct; + gzFile gzdata; /* Set this thread to detached state */ pthread_detach(Dfile->th1); @@ -221,12 +235,23 @@ write(Dfile->FD_Write, buf, strlen(buf)); - /* Append raw file contents */ - while ( (nbytes = read(Dfile->FD, buf, 8192)) != 0 ) { - write(Dfile->FD_Write, buf, nbytes); + /* decompress gzipped file */ + if (Dfile->ContentEncoding == GZIP_ENCODING) { + gzdata = gzdopen(Dfile->FD, "r"); + while ((nbytes = gzread(gzdata, buf, 8192)) != 0 ) { + write(Dfile->FD_Write, buf, nbytes); + } + gzclose(gzdata); } + else { + /* Append raw file contents */ + while ( (nbytes = read(Dfile->FD, buf, 8192)) != 0 ) { + write(Dfile->FD_Write, buf, nbytes); + } + File_close(Dfile->FD); + } File_close(Dfile->FD_Write); File_dillofile_free(Dfile); return NULL; @@ -339,7 +364,7 @@ static void File_get(ChainLink *Info, void *Data1, void *Data2) { const gchar *path; - gchar *filename; + gchar *filename, *tmp_filename; gint fd; struct stat sb; const DilloUrl *Url = Data1; @@ -353,8 +378,15 @@ filename = g_strdup(g_get_home_dir()); else filename = a_Url_parse_hex_path(Url); - +stat_point: if ( stat(filename, &sb) != 0 ) { + char *ext = strrchr(filename, '.'); + if (ext && strcmp(ext, ".gz") != 0) { + tmp_filename = filename; + filename = g_strconcat(tmp_filename, ".gz", NULL); + g_free(tmp_filename); + goto stat_point; + } /* stat failed, prepare a file-not-found error. */ fd = -2; } else if (S_ISDIR(sb.st_mode)) {