Open HaydnTrigg opened 6 years ago
You should probably not use a block size of ~400MB
BZip2.Compress(sourceStream, compressStream, true, 4096);
Giving a block size above 9 should probably throw an exception though. With a block size of 1 it still takes ~15 min to compress your sample file, which is pretty terrible, I'd probably suggest compressing using an external process like 7z as it's way more performant:
> ptime 7z a -tbzip2 _GameMeshTri1_color.blob-7zr.bz2 _GameMeshTri1_color.blob -mx=9
7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04
Scanning the drive:
1 file, 67108900 bytes (65 MiB)
Creating archive: _GameMeshTri1_color.blob-7zr.bz2
Items to compress: 1
Files read from disk: 1
Archive size: 731848 bytes (715 KiB)
Everything is Ok
Execution time: 20.579 s
There might be a bug here though, could you provide another blob that is similar but compresses faster?
I am currently working on replacing the BZip-code (https://github.com/piksel/SharpZipLib/tree/jbzip2) and using that branch it compresses your blob in about 12s on the same machine. It actually passes the tests, but it is not ready for production yet:
I am unable to reproduce this error with any other files, however, its just specifically that file that causes this error. It's interesting to note that in BZip2OutputStream the block size should be within 1-9 range anyway just in case an invalid input is put in.
if (blockSize > 9) {
blockSize = 9;
}
if (blockSize < 1) {
blockSize = 1;
}
Yes, the blockSize was just a red herring.
I just wanted a working sample to use as a comparison when debugging the code.
Steps to reproduce
Code Sample:
Repo with project:
https://github.com/HaydnTrigg/SharpZipLibProblem_GameMeshTri1_color.blob:
_GameMeshTri1_color.blob_GameMeshTri1_color.png:
_GameMeshTri1_color.pngExpected behaviour
BZip2 should compress the file into the output stream "compressStream"
Actual behaviour
BZip2.Compress function never returns The code has been tested with other generated binary data, this just suddenly caused a hang with this specific bit map data.
Version of SharpZipLib
v1.0.0-alpha2 from NuGet
Obtained from (place an x between the brackets for all that apply)