Skip to content

Additional utilities for handling ZIP files#2120

Merged
jodastephen merged 2 commits into
masterfrom
topic/zip-utils
Dec 5, 2019
Merged

Additional utilities for handling ZIP files#2120
jodastephen merged 2 commits into
masterfrom
topic/zip-utils

Conversation

@jodastephen
Copy link
Copy Markdown
Contributor

Extend class to cover more zip/unzip use cases.

* @return the unzipped file, empty if not found
* @throws UncheckedIOException if an IO error occurs
*/
public static Optional<ArrayByteSource> unzipPathNameInMemory(BeanByteSource source, String relativePathName) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A null relative path doesn't make sense, but is currently accepted by this method, and would make it return Optional.empty.

} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return entryNames;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make immutable?

if (deduplicate.add(new ZipKey(entry))) {
ArrayByteSource entrySource = ArrayByteSource.copyOf(ByteStreams.toByteArray(in)).withFileName(entry.getName());
consumer.accept(entry.getName(), entrySource);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

ArrayByteSource source2 = ArrayByteSource.ofUtf8("Hello Planet").withFileName("TestFile2.txt");
ArrayByteSource zipFile = ZipUtils.zipInMemory(ImmutableList.of(source1, source2)).withFileName("Test.foo");

ZipUtils.unzipInMemory(zipFile, (name, extracted) -> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the BiConsumer wasn't invoked at all this test would still pass.

@jodastephen jodastephen merged commit 585f3b4 into master Dec 5, 2019
@delete-merged-branch delete-merged-branch Bot deleted the topic/zip-utils branch December 5, 2019 10:15
@jodastephen jodastephen added this to the v2.7 milestone Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants