borisbrodski / sevenzipjbinding

7-Zip-JBinding
http://sevenzipjbind.sourceforge.net/
Other
173 stars 50 forks source link

Compression level for 7z compression only work in solid mode #28

Open optyfr opened 4 years ago

optyfr commented 4 years ago

When archive is set to solid mode, compression level is respected... but when solid mode is not set, the compression level is not taken into account, it seems to choose a compression method according some sizing rules : whatever the level chosen, the final compression method is always the same for the same archive, but change from one archive to another for the same level, so that : On a 2M archive, il will be LZMA2:20 whatever the level On a 5M archive, il will be LZMA2:21 whatever the level On a 10M archive, it will be LZMA2:22 whatever the level On a 95M archive, it will be LZMA2:24 whatever the level

optyfr commented 4 years ago

Also note that this happens the same with 16.02-2.01 and 9.20-2.00 beta

jinfeihan57 commented 3 years ago

Can you try this CMD ?( show technical information) 7z l -slt archivename

optyfr commented 3 years ago

the difference between the two following is setSolid, setLevel is 9 for both ultra.txt => LZMA:22 (9 blocks) solid+ultra.txt => LZMA2:48m (1 block)

optyfr commented 3 years ago

the difference between the two is setSolid, setLevel is 1 for both fastest.txt => LZMA2:22 (9 blocks) solid+fastest.txt => LZMA2:24 (1 block)

optyfr commented 3 years ago
private void SetOptions(final Object iout) throws SevenZipException
{
    switch(format)
    {
        case SEVEN_ZIP:
            if(iout instanceof IOutFeatureSetSolid)
            {
                System.out.println("Solid : "+session.getUser().getSettings().getProperty(SettingsEnum.sevenzip_solid, true));
                ((IOutFeatureSetSolid) iout).setSolid(session.getUser().getSettings().getProperty(SettingsEnum.sevenzip_solid, true)); //$NON-NLS-1$
            }
            if(iout instanceof IOutFeatureSetLevel)
            {
                System.out.println("Level : "+SevenZipOptions.valueOf(session.getUser().getSettings().getProperty(SettingsEnum.sevenzip_level, SevenZipOptions.NORMAL.toString())).getLevel());
                ((IOutFeatureSetLevel) iout).setLevel(SevenZipOptions.valueOf(session.getUser().getSettings().getProperty(SettingsEnum.sevenzip_level, SevenZipOptions.NORMAL.toString())).getLevel()); //$NON-NLS-1$
            }
            if(iout instanceof IOutFeatureSetMultithreading)
                ((IOutFeatureSetMultithreading) iout).setThreadCount(session.getUser().getSettings().getProperty(SettingsEnum.sevenzip_threads, -1)); //$NON-NLS-1$
            break;
        case ZIP:
            if(iout instanceof IOutFeatureSetLevel)
                ((IOutFeatureSetLevel) iout).setLevel(ZipOptions.valueOf(session.getUser().getSettings().getProperty(SettingsEnum.zip_level, ZipOptions.NORMAL.toString())).getLevel()); //$NON-NLS-1$
            if(iout instanceof IOutFeatureSetMultithreading)
                ((IOutFeatureSetMultithreading) iout).setThreadCount(session.getUser().getSettings().getProperty(SettingsEnum.zip_threads, -1)); //$NON-NLS-1$
        default:
            break;
    }
}

This is the method used to set options for compression, the println showed the right settings used for tests...

optyfr commented 3 years ago

btw, don't try to setThreadCount other than -1 or it won't compress to the desired level at all... even with solid mode!

optyfr commented 3 years ago

also tried to tweak solid mode... and finally the only combination that take care of compression level settings is setSolid(true) without any other options from IOutFeatureSetSolid, I mean that setSolidFiles other than -1 (for example 1 or 2) with setSolid(true) will also break the compression level...

dknchris commented 3 years ago

@borisbrodski This is really becoming a huge deal breaker. setThreadCount() and setSolidSize() both ENFORCE level 9 Ultra compression and disregards whatever level we set via setLevel(). Please prioritize this issue. Can help test this thoroughly on Windows and Android devices.

optyfr, were you able to use any workaround for this issue?