From bd1600a10daeb96a872b656cc1da5693116554ce Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 19 Jan 2017 17:26:42 +0100 Subject: [PATCH] gmio_amf: rename some ZIP fields in gmio_amf_write_options --- src/gmio_amf/amf_io.c | 14 +++++++------- src/gmio_amf/amf_io_options.h | 16 +++++++++++++--- tests/test_amf_io.c | 6 +++--- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/gmio_amf/amf_io.c b/src/gmio_amf/amf_io.c index 54188d4..26b1a29 100644 --- a/src/gmio_amf/amf_io.c +++ b/src/gmio_amf/amf_io.c @@ -725,7 +725,7 @@ static size_t gmio_amf_ostringstream_write( struct gmio_amf_wcontext* context = (struct gmio_amf_wcontext*)cookie; size_t len_written = 0; if (gmio_no_error(context->error)) { - if (context->options->compress) { + if (context->options->create_zip_archive) { len_written = gmio_amf_ostringstream_write_zlib(context, stream, ptr, len); } @@ -833,13 +833,13 @@ static int gmio_amf_write_file_data( return context->error; if (!gmio_amf_write_root_constellations(context)) return context->error; - if (context->options->compress) { + if (context->options->create_zip_archive) { gmio_ostringstream_flush(sstream); context->z_flush = Z_FINISH; } gmio_ostringstream_write_chararray(sstream, "\n"); gmio_ostringstream_flush(sstream); - if (context->options->compress && dd != NULL) { + if (context->options->create_zip_archive && dd != NULL) { dd->crc32 = context->z_crc32; dd->uncompressed_size = context->z_uncompressed_size; dd->compressed_size = context->z_compressed_size; @@ -887,7 +887,7 @@ int gmio_amf_write( context.f64_format.precision = opts->float64_prec != 0 ? opts->float64_prec : 16; - if (opts->compress) { + if (opts->create_zip_archive) { /* Initialize internal zlib stream for compression */ const size_t mblock_halfsize = memblock->size / 2; context.sstream.strbuff.capacity = mblock_halfsize; @@ -907,7 +907,7 @@ int gmio_amf_write( struct gmio_zip_file_entry file_entry = {0}; file_entry.compress_method = GMIO_ZIP_COMPRESS_METHOD_DEFLATE; file_entry.feature_version = - opts->force_zip64_format ? + !opts->dont_use_zip64_extensions ? GMIO_ZIP_FEATURE_VERSION_FILE_ZIP64_FORMAT_EXTENSIONS : GMIO_ZIP_FEATURE_VERSION_FILE_COMPRESSED_DEFLATE; const struct gmio_zip_entry_filename zip_entry_filename = @@ -923,7 +923,7 @@ int gmio_amf_write( } label_end: - if (opts->compress) + if (opts->create_zip_archive) deflateEnd(&context.z_stream); gmio_memblock_helper_release(&mblock_helper); return context.error; @@ -934,7 +934,7 @@ int gmio_amf_write_file( const struct gmio_amf_document* doc, const struct gmio_amf_write_options* opts) { - const bool compress = opts != NULL ? opts->compress : false; + const bool compress = opts != NULL ? opts->create_zip_archive : false; FILE* file = fopen(filepath, compress ? "wb" : "w"); if (file != NULL) { /* TODO: if opts->zip_entry_filename is empty then try to take the diff --git a/src/gmio_amf/amf_io_options.h b/src/gmio_amf/amf_io_options.h index 15146bf..dc2c1f0 100644 --- a/src/gmio_amf/amf_io_options.h +++ b/src/gmio_amf/amf_io_options.h @@ -78,11 +78,21 @@ struct gmio_amf_write_options /* ZIP/Deflate compression */ - bool compress; - struct gmio_zlib_compress_options z_compress_options; + /*! Flag to write AMF geometry in a ZIP archive containing one file entry. + * Options below have no effect if create_zip_archive==false */ + bool create_zip_archive; + + /*! Filename of the single AMF entry within the ZIP archive */ const char* zip_entry_filename; + + /*! Filename length of the single AMF entry within the ZIP archive */ uint16_t zip_entry_filename_len; - bool force_zip64_format; + + /*! Flag to disable use of the Zip64 format extensions */ + bool dont_use_zip64_extensions; + + /*! Options for the deflate(zlib) compression */ + struct gmio_zlib_compress_options z_compress_options; }; #endif /* GMIO_AMF_IO_OPTIONS_H */ diff --git a/tests/test_amf_io.c b/tests/test_amf_io.c index 7da98e4..02a2156 100644 --- a/tests/test_amf_io.c +++ b/tests/test_amf_io.c @@ -306,9 +306,10 @@ static const char* test_amf_write_doc_1_zip() wbuff.pos = 0; struct gmio_amf_write_options options = {0}; options.float64_prec = 9; - options.compress = true; + options.create_zip_archive = true; options.zip_entry_filename = zip_entry_filename; options.zip_entry_filename_len = zip_entry_filename_len; + options.dont_use_zip64_extensions = true; const int error = __tamf__write_amf(&wbuff, &doc, &options); UTEST_COMPARE_INT(error, GMIO_ERROR_OK); #if 1 @@ -390,10 +391,9 @@ static const char* test_amf_write_doc_1_zip64() wbuff.pos = 0; struct gmio_amf_write_options options = {0}; options.float64_prec = 9; - options.compress = true; + options.create_zip_archive = true; options.zip_entry_filename = zip_entry_filename; options.zip_entry_filename_len = zip_entry_filename_len; - options.force_zip64_format = true; const int error = __tamf__write_amf(&wbuff, &doc, &options); UTEST_COMPARE_INT(error, GMIO_ERROR_OK); #if 1