>From a618b9fdd57a9f2d49e1be6bb4e8ca9e88dd8e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Gonz=C3=A1lez?= Date: Wed, 14 Nov 2012 18:56:36 +0100 Subject: [PATCH 2/2] Removed the mixed code and declarations left from warc.c --- src/warc.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/warc.c b/src/warc.c index 04e11e4..2f4fe04 100644 --- a/src/warc.c +++ b/src/warc.c @@ -105,7 +105,7 @@ static int warc_current_file_number; struct hash_table * warc_cdx_dedup_table; static bool warc_start_new_file (bool meta); - +static bool warc_write_skip_length_header (void); struct warc_cdx_record { @@ -300,6 +300,17 @@ warc_write_end_record (void) fflush (warc_current_file); fseeko (warc_current_file, 0, SEEK_END); + return warc_write_skip_length_header(); + } +#endif /* HAVE_LIBZ */ + + return warc_write_ok; +} + +static bool +warc_write_skip_length_header (void) +{ +#ifdef HAVE_LIBZ /* The WARC standard suggests that we add 'skip length' data in the extra header field of the GZIP stream. @@ -319,14 +330,16 @@ warc_write_end_record (void) off_t current_offset = ftello (warc_current_file); off_t uncompressed_size = current_offset - warc_current_gzfile_offset; off_t compressed_size = warc_current_gzfile_uncompressed_size; + char static_header[GZIP_STATIC_HEADER_SIZE]; + char extra_header[EXTRA_GZIP_HEADER_SIZE]; + size_t result; /* Go back to the static GZIP header. */ fseeko (warc_current_file, warc_current_gzfile_offset + EXTRA_GZIP_HEADER_SIZE, SEEK_SET); /* Read the header. */ - char static_header[GZIP_STATIC_HEADER_SIZE]; - size_t result = fread (static_header, 1, GZIP_STATIC_HEADER_SIZE, + result = fread (static_header, 1, GZIP_STATIC_HEADER_SIZE, warc_current_file); if (result != GZIP_STATIC_HEADER_SIZE) { @@ -343,7 +356,7 @@ warc_write_end_record (void) fwrite (static_header, 1, GZIP_STATIC_HEADER_SIZE, warc_current_file); /* Prepare the extra GZIP header. */ - char extra_header[EXTRA_GZIP_HEADER_SIZE]; + /* XLEN, the length of the extra header fields. */ extra_header[0] = ((EXTRA_GZIP_HEADER_SIZE - 2) & 255); extra_header[1] = ((EXTRA_GZIP_HEADER_SIZE - 2) >> 8) & 255; @@ -369,10 +382,8 @@ warc_write_end_record (void) /* Done, move back to the end of the file. */ fflush (warc_current_file); fseeko (warc_current_file, 0, SEEK_END); - } #endif /* HAVE_LIBZ */ - - return warc_write_ok; + return true; } -- 1.8.0