[
https://issues.apache.org/jira/browse/COMPRESS-574?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17324194#comment-17324194
]
Peter Lee commented on COMPRESS-574:
------------------------------------
> _So if a user request download?zip_name=myzip&file_names=A,C_
For this case, I think we can implement it with existing APIs like this :
{code:java}
@Test
public void pickEntriesFromZipAndCreateANewZip() throws IOException {
final Set<String> selectedEntries = new HashSet<>( Arrays.asList(new
String[] {
"src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java",
"src/main/java/org/apache/commons/compress/archivers/zip/UnixStat.java",
"src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java"}));
final ZipFile zipFile = new ZipFile(getFile("ordertest.zip"),
ZipEncodingHelper.UTF8);
final File archive = File.createTempFile("test.", ".zip");;
final ZipArchiveOutputStream zipArchiveOutputStream = new
ZipArchiveOutputStream(archive);
for (final ZipArchiveEntry entry : Collections.list(zipFile.getEntries())) {
if (!selectedEntries.contains(entry.getName())) {
continue;
}
zipArchiveOutputStream.putArchiveEntry(entry);
final InputStream inputStream = zipFile.getInputStream(entry);
IOUtils.copy(inputStream, zipArchiveOutputStream);
inputStream.close();
zipArchiveOutputStream.closeArchiveEntry();
}
zipArchiveOutputStream.close();
// display
final ZipArchiveInputStream zipArchiveInputStream = new
ZipArchiveInputStream(new FileInputStream(archive));
ArchiveEntry entry;
while ((entry = zipArchiveInputStream.getNextEntry()) != null) {
System.out.println(entry.getName());
}
}
{code}
> Byte range support in archive creation
> --------------------------------------
>
> Key: COMPRESS-574
> URL: https://issues.apache.org/jira/browse/COMPRESS-574
> Project: Commons Compress
> Issue Type: Improvement
> Components: Archivers
> Reporter: Gaël Lalire
> Priority: Minor
> Attachments: DynamicZip.java, DynamicZipTest.java
>
>
> When you have a ZIP which contains _N_ components and you want to let the
> user choose which components it needs, you need to create _2^N - 1_ ZIP.
> So the idea is to store each component once (or twice if you want both
> deflated and stored version), and create the ZIP on the fly.
> For the moment you can stream with a ZipOutputStream but if you need an
> InputStream things get a lot harder. I guess programs are writing the ZIP to
> a file system and read from it after, so not really a streaming anymore.
> Also ZipOutputStream will never allow you to resume from a byte range, you
> need to generate all previous data.
> So I made a class to do that, I think such functionality has its place in
> commons compress.
> You can see my code attached and adapt it for better integration / other
> archive type support or simply to get inspired.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)