[ 
https://issues.apache.org/jira/browse/COMPRESS-550?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17179089#comment-17179089
 ] 

Scott Frederick commented on COMPRESS-550:
------------------------------------------

{quote}I think you mean _zip --adjust-sfx test_ instead of _zip --adjust-sfx 
test.zip_ in your example.
{quote}
Yes, thank you. 
{quote}I'm not clear why we need a self-extracting zip. 
{quote}
There are lots of reasons that someone could want a self-extracting zip. The 
example provided was the simplest one I could find to illustrate a workflow 
that's possible with Linux command-line tools but not possible currently with 
Commons Compress. 
{quote}I checked your issue of real-world use case about spring-boot. Seems 
there are Maven/Gradle build plugins that can only produce self-extracting zips 
instead of normal zips. Is it so?
{quote}
The Spring Boot plugins for Maven and Gradle generate Java jar files, which of 
course use the zip format. The jar files can be executed with a _java_ command 
like:
{noformat}
$ java -jar myapp.jar{noformat}
Spring Boot provides an option to prepend an executable script to the generated 
jar file to make it self-executable. If this option is used, the jar file can 
be executed with just: 
{noformat}
$ ./myapp.jar{noformat}
 With this specific use case, the jar/zip is not self-extracting, but is 
self-executing. 

As with the _cat_ example in the CLI workflow, prepending the Spring Boot 
executable script to the jar file results in a file with a central directory 
that is invalid. Spring Boot uses Commons Compress for all jar/zip file reading 
and writing, so having the ability to generate a self-executing jar file with a 
valid central directory using Commons Compress would improve the user 
experience.

> Support writing self-extracting preamble data to a zip archive
> --------------------------------------------------------------
>
>                 Key: COMPRESS-550
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-550
>             Project: Commons Compress
>          Issue Type: New Feature
>          Components: Archivers
>    Affects Versions: 1.20
>            Reporter: Scott Frederick
>            Priority: Major
>
> On Linux, it is possible to create a self-extracting zip file by prepending a 
> script or other executable to the zip file. For example, this can be done 
> from the command line with the following commands: 
> {code:bash}
> $ echo "test file text" > test.txt
> $ zip test.zip test.txt
>   adding: test.txt (stored 0%)
> $ cat /usr/bin/unzipsfx test.zip > test
> $ zipinfo test
> Archive:  test
> Zip file size: 101568 bytes, number of entries: 1
> warning [test]:  101392 extra bytes at beginning or within zipfile
>   (attempting to process anyway)
> -rw-r--r--  3.0 unx       10 tx stor 20-Jul-30 15:43 test.txt
> 1 file, 10 bytes uncompressed, 10 bytes compressed:  0.0%
> $ zip --adjust-sfx test.zip
> Zip entry offsets appear off by 101392 bytes - correcting...
> $ zipinfo test
> Archive:  test
> Zip file size: 101568 bytes, number of entries: 1
> -rw-r--r--  3.0 unx       10 tx stor 20-Jul-30 15:43 test.txt
> 1 file, 10 bytes uncompressed, 10 bytes compressed:  0.0%
> $ chmod 755 test 
> {code}
> Note that the first invocation of "zipinfo" reports that the central 
> directory is invalid because of extra bytes at the beginning of the zip file. 
> "zip --adjust-sfx" can be used to adjust the central directory to account for 
> the self-extracting preamble bytes. 
> It would be nice to be able to prepend this kind of self-extracting preamble 
> to a zip using Apache Commons Compress. 
> A method like the following on ZipArchiveOutputStream seems to provide this 
> behavior: 
> {code:java}
>     public void writePreamble(byte[] preamble) throws IOException {
>         if (entry != null) {
>             throw new IllegalStateException("Preamble must be written before 
> creating an entry");
>         }
>         this.streamCompressor.writeCounted(preamble);
>     }
> {code}
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to