1 --- dillo-0.7.2/src/IO/file.c.orig Sun May 4 12:33:54 2003
2 +++ dillo-0.7.2/src/IO/file.c Sun May 4 12:57:50 2003
6 #include <math.h> /* for rint */
9 #include <errno.h> /* for errno */
12 gint FD; /* Our local-file descriptor */
15 + gint ContentEncoding; /* 0 normal, 1 gzipped */
17 pthread_t th1; /* This transfer's thread id. */
21 +#define GZIP_ENCODING 1
29 + gint ContentEncoding; /* 0 normal, 1 gzipped */
32 - if ( (fd = open(filename, O_RDONLY)) < 0 || pipe(fds) )
33 + if ( (fd = open(filename, O_RDONLY)) < 0 || pipe(fds) ) {
37 + if (strncmp(strrchr(filename, '.'), ".gz", 3) == 0)
38 + ContentEncoding = GZIP_ENCODING;
39 Dfile = g_new(DilloFile, 1);
40 Dfile->FD_Read = fds[0];
41 Dfile->FD_Write = fds[1];
43 Dfile->FileName = g_strdup(filename);
44 - Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size;
45 + if (ContentEncoding == GZIP_ENCODING) {
46 + gchar *tmp_filename = g_strndup(filename, strlen(filename) - 3);
47 + g_free(tmp_filename);
48 + Dfile->FileSize = -1;
51 + Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size;
53 + Dfile->ContentEncoding = ContentEncoding;
58 DilloFile *Dfile = data;
63 /* Set this thread to detached state */
64 pthread_detach(Dfile->th1);
66 write(Dfile->FD_Write, buf, strlen(buf));
69 - /* Append raw file contents */
70 - while ( (nbytes = read(Dfile->FD, buf, LBUF)) != 0 ) {
71 - write(Dfile->FD_Write, buf, nbytes);
72 + /* decompress gzipped file */
73 + if (Dfile->ContentEncoding == GZIP_ENCODING) {
74 + gzdata = gzdopen(Dfile->FD, "r");
75 + while ((nbytes = gzread(gzdata, buf, 8192)) != 0 ) {
76 + write(Dfile->FD_Write, buf, nbytes);
81 + /* Append raw file contents */
82 + while ( (nbytes = read(Dfile->FD, buf, LBUF)) != 0 ) {
83 + write(Dfile->FD_Write, buf, nbytes);
87 File_close(Dfile->FD);
89 File_close(Dfile->FD_Write);
90 File_dillofile_free(Dfile);
93 static void File_get(ChainLink *Info, void *Data1, void *Data2)
97 + gchar *filename, *tmp_filename;
100 const DilloUrl *Url = Data1;
102 filename = g_strdup(g_get_home_dir());
104 filename = a_Url_parse_hex_path(Url);
107 if ( stat(filename, &sb) != 0 ) {
108 + char *ext = strrchr(filename, '.');
109 + if (ext && strcmp(ext, ".gz") != 0) {
110 + tmp_filename = filename;
111 + filename = g_strconcat(tmp_filename, ".gz", NULL);
112 + g_free(tmp_filename);
115 /* stat failed, prepare a file-not-found error. */
117 } else if (S_ISDIR(sb.st_mode)) {