Skip to content

Commit

Permalink
#3 Store compression optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-cherednik committed Oct 27, 2024
1 parent 7f36410 commit eae4568
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public CentralDirectory.FileHeader getFileHeader(String entryName) throws IOExce
.findFirst().orElseThrow(() -> new EntryNotFoundException(entryName));
}

private BlockModel createModel() throws IOException {
public BlockModel createModel() throws IOException {
BlockZipModelReader reader = new BlockZipModelReader(srcZip,
settings.getCustomizeCharset(),
settings.getPasswordProvider());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public final class BlockModel {
private final Block endCentralDirectoryBlock;
private final Zip64Block zip64Block;
private final BaseCentralDirectoryBlock centralDirectoryBlock;

private final Map<String, ZipEntryBlock> fileNameZipEntryBlock;

public static Builder builder() {
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/ru/olegcherednik/zip4jvm/TestDataAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ public final class TestDataAssert {
fileSuzukiAssert.accept(dir.regularFile(fileNameSuzuki));
};

public static final long fileBentleySize = 1_395_362;

public static final Consumer<IRegularFileAssert<?>> fileBentleyAssert =
file -> file.exists().hasSize(1_395_362).isImage().isContentEqualTo(fileBentley);
file -> file.exists().hasSize(fileBentleySize).isImage().isContentEqualTo(fileBentley);
public static final Consumer<IRegularFileAssert<?>> fileFerrariAssert =
file -> file.exists().hasSize(320_894).isImage().isContentEqualTo(fileFerrari);
public static final Consumer<IRegularFileAssert<?>> fileWiesmannAssert =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package ru.olegcherednik.zip4jvm;

import ru.olegcherednik.zip4jvm.engine.InfoEngine;
import ru.olegcherednik.zip4jvm.model.Compression;
import ru.olegcherednik.zip4jvm.model.CompressionMethod;
import ru.olegcherednik.zip4jvm.model.LocalFileHeader;
import ru.olegcherednik.zip4jvm.model.block.BlockModel;
import ru.olegcherednik.zip4jvm.model.block.ZipEntryBlock;
import ru.olegcherednik.zip4jvm.model.settings.ZipInfoSettings;
import ru.olegcherednik.zip4jvm.model.settings.ZipSettings;
import ru.olegcherednik.zip4jvm.model.src.SrcZip;

import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;
import static ru.olegcherednik.zip4jvm.TestData.fileBentley;
import static ru.olegcherednik.zip4jvm.TestData.fileNameBentley;
import static ru.olegcherednik.zip4jvm.TestDataAssert.fileBentleySize;

/**
* @author Oleg Cherednik
* @since 27.10.2024
*/
@Test
@SuppressWarnings("FieldNamingConvention")
public class ZipCompressionOptimizationTest {

private static final Path rootDir = Zip4jvmSuite.generateSubDirNameWithTime(ZipCompressionOptimizationTest.class);

public void shouldNotCreateDataDescriptionWhenStoreCompression() throws IOException {
Path parent = Zip4jvmSuite.subDirNameAsMethodName(rootDir);
Path zip = parent.resolve("src.zip");
ZipIt.zip(zip).settings(ZipSettings.of(Compression.STORE)).add(fileBentley);

InfoEngine infoEngine = new InfoEngine(SrcZip.of(zip), ZipInfoSettings.builder().readEntries(true).build());
BlockModel blockModel = infoEngine.createModel();

ZipEntryBlock entryBlock = blockModel.getZipEntryBlock(fileNameBentley);
assertThat(entryBlock).isNotNull();
assertThat(entryBlock.getDataDescriptor()).isNotNull();

LocalFileHeader localFileHeader = entryBlock.getLocalFileHeader();
assertThat(localFileHeader).isNotNull();
assertThat(localFileHeader.getCompressionMethod()).isSameAs(CompressionMethod.STORE);
assertThat(localFileHeader.getGeneralPurposeFlag().isDataDescriptorAvailable()).isTrue();
// assertThat(localFileHeader.getCrc32()).isEqualTo(1903786344L);
// assertThat(localFileHeader.getCompressedSize()).isEqualTo(fileBentleySize);
// assertThat(localFileHeader.getUncompressedSize()).isEqualTo(fileBentleySize);
}

}

0 comments on commit eae4568

Please sign in to comment.