Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-550

Support writing self-extracting preamble data to a zip archive

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.20
    • 1.21
    • Archivers
    • None

    Description

      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: 

      $ 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 
      

      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: 

          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);
          }
      

       

       

      Attachments

        Issue Links

          Activity

            People

              peterlee Peter Lee
              scottyfred Scott Frederick
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 40m
                  1h 40m