From 8a5c590389f5a6704300a583827ac7ee982a8d73 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sun, 24 Feb 2019 10:46:08 +0100 Subject: [PATCH] serial/Exporter: Better zip/noZip choice --- src/be/nikiroo/utils/serial/Exporter.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/be/nikiroo/utils/serial/Exporter.java b/src/be/nikiroo/utils/serial/Exporter.java index 9093988..3a6e025 100644 --- a/src/be/nikiroo/utils/serial/Exporter.java +++ b/src/be/nikiroo/utils/serial/Exporter.java @@ -59,18 +59,21 @@ public class Exporter { * The exported items in a serialised form. * * @param zip - * TRUE to have zipped content, FALSE to have raw content, NULL - * to let the system decide + * TRUE to have zipped (and BASE64-coded) content, FALSE to have + * raw content, NULL to let the system decide * * @return the items currently in this {@link Exporter} */ public String toString(Boolean zip) { - if (zip == null) { - zip = builder.length() > 128; + if (zip == null && builder.length() > 128) { + zip = false; } - if (zip) { - return "ZIP:" + StringUtils.zip64(builder.toString()); + if (zip == null || zip) { + String zipped = "ZIP:" + StringUtils.zip64(builder.toString()); + + if (zip != null || builder.length() < zipped.length()) + return zipped; } return builder.toString(); -- 2.27.0