Skip to content

Commit

Permalink
[Issue #173] Fix loading the first image from a 7zip encoded archive. (
Browse files Browse the repository at this point in the history
…#174)

* [Issue #173] Replace old 7zip example comic with a new one.

* [Issue #173] Archive adaptors reset their reading position when finding the cover image.
  • Loading branch information
mcpierce committed Mar 9, 2020
1 parent d74bfe0 commit 8c569ac
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Expand Up @@ -281,13 +281,17 @@ protected File validateFile(Comic comic) throws ArchiveAdaptorException {

@Override
public String getFirstImageFileName(String filename) throws ArchiveAdaptorException {
I archiveRef = this.openArchive(new File(filename));
I archiveRef = null;

// get the list of entries
archiveRef = this.openArchive(new File(filename));
List<String> entries = this.getEntryFilenames(archiveRef);
Collections.sort(entries);
String result = null;
this.closeArchive(archiveRef);

for (String entry : entries) {
archiveRef = this.openArchive(new File(filename));
byte[] content = this.loadSingleFileInternal(archiveRef, entry);
String contentType = this.fileTypeIdentifier.subtypeFor(new ByteArrayInputStream(content));

Expand Down
Expand Up @@ -121,6 +121,7 @@ protected void loadAllFiles(Comic comic, SevenZFile archiveReference)
protected byte[] loadSingleFileInternal(SevenZFile archiveReference, String entryName)
throws ArchiveAdaptorException {
byte[] result = null;

try {
boolean done = false;
SevenZArchiveEntry entry = archiveReference.getNextEntry();
Expand Down
Expand Up @@ -35,16 +35,16 @@
@SpringBootTest(classes = ComiXedTestContext.class)
@TestPropertySource(locations = "classpath:application.properties")
public class SevenZipArchiveAdaptorTest {
private static final String TEST_FILE_ENTRY_3 = "exampleCBR.jpg";
private static final String TEST_FILE_ENTRY_2 = "example.png";
private static final String TEST_FILE_ENTRY_2 = "exampleCBR.jpg";
private static final String TEST_FILE_ENTRY_3 = "example.png";
private static final String TEST_FILE_ENTRY_1 = "example.jpg";
private static final String TEST_FILE_ENTRY_0 = "example.jpeg";
private static final String TEST_CB7_FILE = "target/test-classes/example.cb7";
private static final String TEST_CBR_FILE = "target/test-classes/example.cbr";
private static final Object TEST_FILE_ENTRY_RENAMED_0 = "offset-000.jpeg";
private static final Object TEST_FILE_ENTRY_RENAMED_1 = "offset-001.jpg";
private static final Object TEST_FILE_ENTRY_RENAMED_2 = "offset-002.png";
private static final Object TEST_FILE_ENTRY_RENAMED_3 = "offset-003.jpg";
private static final Object TEST_FILE_ENTRY_RENAMED_2 = "offset-002.jpg";
private static final Object TEST_FILE_ENTRY_RENAMED_3 = "offset-003.png";

@Autowired private SevenZipArchiveAdaptor archiveAdaptor;

Expand Down
Binary file modified comixed-library/src/test/resources/example.cb7
Binary file not shown.

0 comments on commit 8c569ac

Please sign in to comment.