Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion cdm/core/src/main/java/ucar/nc2/write/Nc4ChunkingStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

package ucar.nc2.write;

import ucar.ma2.DataType;
import ucar.nc2.Attribute;
import ucar.nc2.Structure;
import ucar.nc2.Variable;
import ucar.nc2.constants.CDM;
import javax.annotation.concurrent.Immutable;
Expand Down Expand Up @@ -52,7 +54,20 @@ protected Nc4ChunkingStrategy(int deflateLevel, boolean shuffle) {

@Override
public int getDeflateLevel(Variable v) {
return deflateLevel;
return isCompressible(v) ? deflateLevel : 0;
}

// compression should not be applied to variable-sized variables
// see Unidata/netcdf-java#1420
private boolean isCompressible(Variable v) {
if (v.getDataType().equals(DataType.STRING) || v.isVariableLength())
return false;

if (v.getDataType().equals(DataType.STRUCTURE)) {
Structure s = (Structure) v;
return s.getVariables().stream().allMatch(this::isCompressible);
}
return true;
}

@Override
Expand Down