From owner-p4-projects@FreeBSD.ORG Tue Dec 9 16:00:59 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3C7411065689; Tue, 9 Dec 2008 16:00:59 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 009791065688 for ; Tue, 9 Dec 2008 16:00:59 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id E3DE78FC16 for ; Tue, 9 Dec 2008 16:00:58 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id mB9G0wNO029888 for ; Tue, 9 Dec 2008 16:00:58 GMT (envelope-from strauss@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id mB9G0wwI029886 for perforce@freebsd.org; Tue, 9 Dec 2008 16:00:58 GMT (envelope-from strauss@FreeBSD.org) Date: Tue, 9 Dec 2008 16:00:58 GMT Message-Id: <200812091600.mB9G0wwI029886@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to strauss@FreeBSD.org using -f From: Anselm Strauss To: Perforce Change Reviews Cc: Subject: PERFORCE change 154398 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Dec 2008 16:00:59 -0000 http://perforce.freebsd.org/chv.cgi?CH=154398 Change 154398 by strauss@strauss_silversurfer on 2008/12/09 16:00:15 Added deflate compression, still compile problems (linking) Affected files ... .. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#42 edit Differences ... ==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#42 (text+ko) ==== @@ -76,6 +76,11 @@ #define ZIP_VERSION_BY 0x0314 /* Made by UNIX, using ZIP version 2.0. */ #define ZIP_FLAGS 0x08 /* Flagging bit 3 (count from 0) for using data descriptor. */ +enum compression { + COMPRESSION_STORE = 0, + COMPRESSION_DEFLATE = 6 +}; + static ssize_t archive_write_zip_data(struct archive_write *, const void *buff, size_t s); static int archive_write_zip_finish(struct archive_write *); static int archive_write_zip_destroy(struct archive_write *); @@ -177,11 +182,6 @@ char comment_length[2]; }; -static enum compression { - COMPRESSION_STORE = 0, - COMPRESSION_DEFLATE = 6 -}; - int archive_write_set_format_zip(struct archive *_a) { @@ -294,7 +294,7 @@ zip_encode(path_length(entry), &h.filename_length, sizeof(h.filename_length)); zip_encode(sizeof(e), &h.extra_length, sizeof(h.extra_length)); - if (zip->compression = COMPRESSION_STORE) { + if (zip->compression == COMPRESSION_STORE) { /* Setting compressed and uncompressed sizes even when specification says * to set to zero when using data descriptors. Otherwise the end of the * data for an entry is rather difficult to find. */ @@ -342,35 +342,62 @@ struct zip *zip = a->format_data; struct zip_file_header_link *l = zip->central_directory_end; z_stream stream; + size_t chunk = sizeof(*buff); + unsigned char buff_out[chunk]; if (s > zip->remaining_data_bytes) s = zip->remaining_data_bytes; + + if (s == 0) return 0; switch (zip->compression) { case COMPRESSION_STORE: ret = (a->compressor.write)(a, buff, s); + if (ret < 0) return (ret); + zip->written_bytes += s; + zip->remaining_data_bytes -= s; + l->crc32 = crc32(l->crc32, buff, s); + return (ret); case COMPRESSION_DEFLATE: - deflateInit2( - stream, - - ); + stream.zalloc = Z_NULL; + stream.zfree = Z_NULL; + stream.opaque = Z_NULL; + ret = deflateInit(&stream, Z_DEFAULT_COMPRESSION); + if (ret != Z_OK) return (ARCHIVE_FATAL); + stream.next_in = (unsigned char*) buff; + stream.avail_in = s; + do { + stream.next_out = buff_out; + stream.avail_out = chunk; + ret = deflate(&stream, Z_FINISH); + if (ret == Z_STREAM_ERROR) { + deflateEnd(&stream); + return (ARCHIVE_FATAL); + } + ret = (a->compressor.write)(a, buff_out, stream.avail_out); + if (ret < 0) { + deflateEnd(&stream); + return (ret); + } + zip->written_bytes += ret; + } while (stream.avail_out == 0); + zip->remaining_data_bytes -= s; + l->crc32 = crc32(l->crc32, buff, s); + deflateEnd(&stream); + return (s); + default: + + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Invalid ZIP compression type"); + return ARCHIVE_FATAL; } /* TODO: set compressed size in data descriptor and local file header link */ - if (ret >= 0) { - zip->written_bytes += s; - zip->remaining_data_bytes -= s; - l->crc32 = crc32(l->crc32, buff, s); - return (s); - } else { - return (ret); - } } static int @@ -434,7 +461,7 @@ zip_encode(dos_time(archive_entry_mtime(l->entry)), &h.timedate, sizeof(h.timedate)); zip_encode(l->crc32, &h.crc32, sizeof(h.crc32)); /* TODO: write compressed size */ - zip_encode(archive_entry_size(entry), &h.uncompressed_size, sizeof(h.uncompressed_size)); + zip_encode(archive_entry_size(l->entry), &h.uncompressed_size, sizeof(h.uncompressed_size)); zip_encode(path_length(l->entry), &h.filename_length, sizeof(h.filename_length)); zip_encode(sizeof(e), &h.extra_length, sizeof(h.extra_length)); mode = archive_entry_mode(l->entry); @@ -588,7 +615,7 @@ set_compression(struct archive_write *a, enum compression compression) { /* TODO: check archive state, should not switch between header and data */ - /* TODO: check if valid compression? */ - a->format_data->compression = compression; + struct zip *zip = a->format_data; + zip->compression = compression; }