gmio_amf: rename some ZIP fields in gmio_amf_write_options

This commit is contained in:
Hugues Delorme 2017-01-19 17:26:42 +01:00
parent abb7bafc4a
commit bd1600a10d
3 changed files with 23 additions and 13 deletions

View File

@ -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, "</amf>\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

View File

@ -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 <tt>create_zip_archive==false</tt> */
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 */

View File

@ -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